Under Radasm, the assembly language implements the bubbling sort

Source: Internet
Author: User

.686p
. Model Flat,stdcall
Option Casemap:none


Include Windows.inc
Include Kernel32.inc
Include Masm32.inc
Includelib "D:\vs\msvcrt.lib"

Includelib Masm32.lib
Includelib Kernel32.lib
printf PROTO C:dword,:vararg
scanf PROTO C:dword,:vararg

. Data
Hello db ' Hello ', 0
A DWORD 5,4,30,2,1
P byte '%s ', 0ah
Hint1 byte "Please enter 5 numbers:", 0ah,0
Hint2 byte "like 5 2 3 1 4,", 0ah,0
FMT byte "%d%d%d%d%d", 0ah,0
Lin byte "function:%d", 0ah,0
Edii byte "Before exchanging eax:%d,ebx:%d", 0ah,0
Edia byte "After exchanging eax:%d,ebx:%d", 0ah,0
. Code

Start
Init:
MOV edi,0
MOV esi,0
JMP Input_number
Input_number:
Invoke printf, offset hint1
Invoke printf, offset hint2
Invoke scanf, offset fmt,offset a[0],offset a[4],offset a[8],offset a[12],offset a[16]
JMP judge
Judge
CMP edi,4
JNS Ju_esi

MOV eax,a[edi*4]
MOV ebx,a[edi*4+4]
; Invoke Printf,offset lin,2
Add edi,1

CMP EAX,EBX
JNS Exchange; The result is negative, the transfer
JMP judge

Exchange
; Invoke Printf,offset EDII,EAX,EBX
MOV a[edi*4-4],ebx
MOV a[edi*4],eax
; Invoke Printf,offset EDIA,EAX,EBX
; invoke printf, offset fmt,a[0],a[4],a[8],a[12],a[16]
JMP judge

Ju_esi:
; Invoke Printf,offset lin,3
Add esi,1
CMP esi,4
JNS exit
MOV edi,0
JMP judge

Exit
; Invoke Printf,offset lin,4
Invoke printf, offset fmt,a[0],a[4],a[8],a[12],a[16]
; invoke StdOut, addr Hello
Invoke exitprocess,0

End Start


Under Radasm, the assembly language implements the bubbling sort

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.