c - Printing bigger number in NASM -
i'm starting learning assembly , i've encountered little problem. i'm trying code program takes 2 integers , prints bigger one. want using printf , scanf c. unfortunately wrote returns second value , keep wondering why. here's code:
extern printf extern scanf global main section .text main: push rbp ;input of first number mov rdi, fmt mov rsi, number1 xor rax, rax call scanf ;input of second number mov rdi, fmt mov rsi, number2 xor rax, rax call scanf ;comparing numbers mov rdx, qword [number1] cmp rdx, qword [number2] jl _1issmaller jge _2issmaller _1issmaller: ;1st number smaller mov rdi, fmt_out mov rsi, qword [number1] xor rax, rax call printf jmp _exit _2issmaller: ;2nd number smaller mov rdi, fmt_out mov rsi, qword [number2] xor rax, rax call printf jmp _exit _exit: pop rbp mov rax, 0 mov rbx, 1 int 80h section .data fmt db "%d", 0 fmt_out db "smaller number: %d", 10, 0 number1 dd 0 number2 dd 0
is there can me? in advance
you have defined numbers (number1
, number2
) dword
s dd
in .data
-section, you're referencing them qword
s cmp
.
so result quite unpredictable/depending on memory layout.
Comments
Post a Comment