;guessing asm
extern printf
extern scanf
extern exit
global main
section .text
main:
;printf(format)
mov rdi, format
mov rax, 0
push rbx
call printf
pop rbx
;scanf(num)
mov rdi, inputformat
mov rsi, num
mov rax, 0
push rbx
call scanf
pop rbx
;printf(question)
mov rdi, question
mov rax, 0
push rbx
call printf
pop rbx
mov rbx, 0 ;total
mov r8, 0 ;yes count
mov r9, 0 ;no count
countingloop:
cmp rbx, [num]
je summary
;scanf(number)
mov rdi, inputformat
mov rsi, number
mov rax, 0
push rbx
call scanf
pop rbx
cmp rsi, 0
je addnocount
cmp rsi, 1
je addyescount
addnocount:
inc rbx
inc r8
jmp countingloop
addyescount:
inc rbx
inc r9
jmp countingloop
summary:
;printf(yesformat)
mov rdi, yesformat
mov rsi, r9 ;question
mov rax, 0
push rbx
call printf
pop rbx
;printf(noformat)
mov rdi, noformat
mov rsi, r8 ;question
mov rax, 0
push rbx
call printf
pop rbx
; exit(0)
mov rax, 0
call exit
section .data
format db "Enter a number of total people", 0ah, 0dh, 0
question db "Do you like dogs yes is 1, no is 0", 0
inputformat db "%d", 0
num dq 0
number dq 0
yesformat db "%d yes counted", 0ah, 0dh, 0
noformat db "%d no counted", 0ah, 0dh, 0