-
Notifications
You must be signed in to change notification settings - Fork 16
/
c03-01.asm
41 lines (26 loc) · 919 Bytes
/
c03-01.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
[org 0x0100]
jmp start
data: dw 6, 4, 5, 2
start:
mov cx, 4 ; make 4 passes, has to be outside the loop!
outerloop:
mov bx, 0
innerloop:
mov ax, [data + bx]
cmp ax, [data + bx + 2] ; why did we move the value to AX?
jbe noswap ; if we don't have to swap, we just jump over the swap thing
; think of this as the "if"
; the swap potion
mov dx, [data + bx + 2]
mov [data + bx + 2], ax ; again with the AX?
mov [data + bx], dx
noswap:
add bx, 2
cmp bx, 6
jne innerloop
; check outer loop termination
sub cx, 1
jnz outerloop
; exit system call
mov ax, 0x4c00
int 0x21