_EXIT _PRINTF 127 _PUTCHAR 122 SECT TEXT PUSH arr PUSH len CALL PRINT_

 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
_EXIT = 1
_PRINTF = 127
_PUTCHAR = 122
.SECT .TEXT
PUSH arr
PUSH len
CALL PRINT_ARR
ADD SP, 4
PUSH 0
PUSH _EXIT
SYS
PRINT_ARR:
PUSH BP
MOV BP, SP
PUSH BX
MOV BX, 6(BP)
PUSH CX
MOV CX, 0
PUSH DX
MOV DX, 4(BP)
1:
PUSH (BX)
PUSH fmt
PUSH _PRINTF
SYS
ADD SP, 6
ADD BX, 2
INC CX
CMP CX, DX
JL 1b
PUSH '\n'
PUSH _PUTCHAR
SYS
ADD SP, 4
POP DX
POP CX
POP BX
MOV SP, BP
POP BP
RET
.SECT .DATA
len: .WORD 5
arr: .WORD 2, -5, 3, 8, 1
end: .BYTE 0
fmt: .ASCIZ "%d "
.SECT .BSS