linux - Basic assembly calculator assignment not working -


we need addition, subtraction, multiplication , division single digits entered in using syscalls. reason addition thing works. cannot figure out why rest don't work. of them outputs nothing, except multiplication works if multiply 1.

my subtract code:

segment .data     1 db 0     2 db 0     diff db 0  segment .text global _start  _start:     mov rax, 0     mov rdi, 0     lea rsi, [one]     mov rdx, 2     syscall     mov rbx, [one]     sub rbx, 48     mov rax, 0     mov rdi, 0     lea rsi, [two]     mov rdx, 2     syscall     sub rbx, [two]     mov [diff], rbx     ;xor rbx, rbx     mov rax, 1     mov rdi, 1     mov rdx, 1     lea rsi, [diff]     syscall     mov rax, 60     xor rdi, rdi     syscall 

my multiplication code:

segment .data 1 db 0 2 db 0 multi db 0  segment .text global _start  _start: mov eax, 0 mov edi, 0 lea esi, [one] mov edx, 2 syscall ;mov ebx, [one] ;sub ebx, '0' mov eax, 0 mov edi, 0 lea rsi, [two] mov edx, 2 syscall mov eax, [one] sub eax, '0' ;mov ecx, [two] ;sub ecx, '0' mul dword [two] mov [multi], eax  xor edx, edx mov eax, 1 mov edi, 1 mov edx, 1 lea esi, [multi] syscall mov eax, 60 xor edi, edi syscall 

and division code:

segment .data 1 db 0 2 db 0 qout db 0  segment .text global _start  _start: mov rax, 0 mov rdi, 0 lea rsi, [one] mov rdx, 2 syscall ;mov rbx, [one] ;sub rbx, '0' mov rax, 0 mov rdi, 0 lea rsi, [two] mov edx, 2 syscall mov eax, [one] sub eax, '0' mov edx, 0 mov ecx, 2 ;sub ecx, '0' div ecx mov [qout], [rax] ;xor rdx, rdx mov rax, 1 mov rdi, 1 mov rdx, 1 lea rsi, [qout] syscall mov rax, 60 xor rdi, rdi syscall 

can please tell me why not working.

this addition reference:

segment .data 1 db 0 2 db 0 sum db 0  segment .text global _start  _start: mov eax, 0 ;read mov edi, 0 ;file descriptor lea esi, [one] ;write 1 mov edx, 2 ;size of input in bytes syscall mov ebx, [one] sub ebx, '0' ;'convert' int mov eax, 0 ;again input mov edi, 0 lea rsi, [two] mov edx, 2 syscall add ebx, [two] ;add 2 1 mov [sum], ebx ;move sum [sum] xor ebx, ebx ;clear register mov eax, 1 ;syscall write mov edi, 1 ;file descriptor mov edx, 1 ;output 1 byte lea esi, [sum] ;output sum syscall mov eax, 60 ;syscall 60 exit xor edi, edi ;exit(0) syscall 

i found solution. in code subtracted '0' both numbers , after operation added '0' again.for division did solution this question suggested.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -