2018/Day01/Day1A.s

53 lines
707 B
ArmAsm
Raw Permalink Normal View History

2019-12-08 11:27:24 +00:00
extern printf
extern scanf
;;;;;;;;;;;;
;;; TEXT ;;;
;;;;;;;;;;;;
section .text
global main
main:
sub rsp, 8
xor rcx, rcx
.loop:
lea rdi, [rel format]
lea rsi, [rel operation]
lea rdx, [rel count]
xor ax, ax
call scanf
xor rax, rax
mov eax, [rel count]
cmp byte [rel operation], '+'
je .add
neg rax
.add:
add rcx, rax
push rcx
lea rdi, [rel message]
mov rsi, rcx
xor ax, ax
call printf
pop rcx
jmp .loop
add rsp, 8
ret
;;;;;;;;;;;;
;;; DATA ;;;
;;;;;;;;;;;;
section .data
format: db "%c%d",0
message: db "%d",10,0
section .bss
buffer: resb 64
operation: resb 1
count: resb 4