Bubble sort in protected mode

Source: Internet
Author: User

1 ;16-bit code2[Bits -]3 ;Initialize data segments, code snippets, stack segments in real mode4         moveax, CS5         movSS, eax6         movSP, 0x7c00;The stack in real mode is below the boot sector7 ;converts a linear address in protected mode to a segment address in real mode: The form of an offset address8         XORedx, edx;use 64-bit division here, high 32-bit clear 09         movEAX, [CS:Gdt_base + 0x7c00];accessing data using the Transcend segment prefixTen         movEbx -                     ;Linear address = Segment Address X 16 + offset address One         Divebx A ;set a data segment that points to a descriptor -         movEBX, edx;the remainder is an offset address -         movds, EAX the ;Install data Segment Descriptor -     ;#0空描述符 -         movDWORD [ebx + 0x00], 0x0000_0000 -         movDWORD [ebx + 0x04], 0x0000_0000 +     ;#1代码段 -         movDWORD [ebx + 0x08], 0x7c00_01ff +         movDWORD [ebx + 0x0C], 0x0040_9800 A     ;#2数据段 at         movDWORD [ebx + 0x10], 0x0000_ffff -         movDWORD [ebx + 0x14], 0x00cf_9200 -     ;#3别名代码段 -         movDWORD [ebx + 0x18], 0x7c00_01ff -         movDWORD [ebx + 0x1C], 0x0040_9200 -     ;#4堆栈段 in         movDWORD [ebx + 0x20], 0X0000_6BFF -         movDWORD [ebx + 0x24], 0x0040_9600 to ;load GDT +         movWord [CS:gdt_size + 0x7c00], 0x27 -         LGDT[CS:gdt_size + 0x7c00] the ;Open A20 *     inchal, 0x92 $     oral, 0000_0010bPanax Notoginseng      out0x92, Al - ;off Interrupt the     CLI + ;Enter protection mode (16-bit) A     moveax, Cr0 the     oreax, 0000_0001b +     movCR0, eax - ;Enter protection mode (32-bit) $     jmpDWORD 0x08:Flush $ ;32-bit code -[Bits +] -     Flush: the     ;Load alias code snippet -     moveax, 0x18Wuyi     movds, EAX the      -     ;Loading Data Segments Wu     moveax, 0x10 -     moves, eax About      $     ;Load Stack -     moveax, 0x20 -     movSS, eax -     movESP, 0X0000_7BFF A      +     ;start the message character on the screen the         movecx, Gdt_size-welcome -         XORebx, ebx $     wel: the         moval, [ebx + welcome] the         movAh, 0x0A the         mov[es:0x000b_8000 + ebx *2], Ax the         Incebx - Loop wel in     ;Bubble Sort the         movECX, Welcome-string-1 the     external: About         XORebx, ebx the         Pushecx the     internal: the         movAX, [ebx + string] +         CMPAh, Al -         JGCon the         XchgAh, AlBayi         movWord [ebx + string], ax the     Con: the         Incebx - Loop Internal -         Popecx the Loop External the     ;Show the results of a sort the     movecx, welcome-string the         XORebx, ebx -     Res: the         moval, [ebx + string] the         movAh, 0x0A the         mov[es:0x000b_8000 + the+ EBX *2], Ax94         Incebx the Loop Res the     ;Downtime the          hlt 98 ;the string to be sorted About         string:Db'958458456541186545552135789642589103598416552556' -         Welcome:Db'Welcome to Lixiaomao boot.'101 ;GDT Locations and Boundaries102         gdt_size:Dw0                ;This word is used to store the boundaries of GDT.103         gdt_base:DD 0x0000_7e00;I 'm going to put the GDT behind the boot sector.104 ;fill the remaining sectors theTimes510-($-$$) DB0106DB 0x55, 0xAA

Bubble sort in protected mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.