-
Notifications
You must be signed in to change notification settings - Fork 0
/
exe.asm
42 lines (40 loc) · 803 Bytes
/
exe.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
39
40
41
42
; nasm -f elf64 -l exe.lst exe.asm && gcc -m64 -o exe exe.o && ./exe
extern printf, atoi, getchar, scanf
SECTION .data ; data section
readint: db "%d%*c",0
msg: db "Case #%d: %d",10,0
len: equ $-msg
count: dq 0
curcount: dq 1
SECTION .text ; code section
global main ; make label available to linker
nextint:
push rsi
push rdi
sub rsp, 8
mov rsi, rsp
mov rdi, readint
xor al, al
call scanf
pop rax
pop rdi
pop rsi
ret
main:
; read number of cases
call nextint
mov [count], rax
countloop:
; print case result
mov rdx, 1
mov rsi, [curcount]
mov rdi, msg
xor rax, rax
call printf
; inc case count
mov rcx, [curcount]
inc rcx
cmp rcx, [count]
mov [curcount], rcx
jle countloop
exit: