
marcozpires
(usa Debian)
Enviado em 18/11/2016 - 08:36h
Sou iniciante em linux e Assembly.
Estou com duvidas de como colocar a função de subtrair no Assembly. Estou usando nasm.
Segue código faltando a função de subtrair:
sys_exit equ 1
sys_read equ 3
sys_write equ 4
stdin equ 0
stdout equ 1
SECTION .data
len EQU 32
msg1 db "Entre com o 1o número: ", 0
msg1len EQU $-msg1
msg2 db "Entre com o 2o número: ", 0
msg2len EQU $-msg2
msg3 db "1-Soma / 2-Subtrai",0x0a
msg3len EQU $-msg3
msg4 db "Entre com o código da operação: ", 0
msg4len EQU $-msg4
formatin: db "%d", 0
formatout: db "Resultado da operação: %d", 10, 0 ; newline, nul terminator
nr1 times 4 db 0
nr2 times 4 db 0
code times 4 db 0
zero times 4 db 0
SECTION .bss
cont resb len
SECTION .text
global main
extern scanf
extern printf
main:
mov eax, sys_write
mov ebx, stdout
mov ecx, msg1
mov edx, msg1len
int 80h
push nr1
push formatin
call scanf
mov eax, sys_write
mov ebx, stdout
mov ecx, msg2
mov edx, msg2len
int 80h
push nr2
push formatin
call scanf
mov eax, sys_write
mov ebx, stdout
mov ecx, msg3
mov edx, msg3len
int 80h
mov eax, sys_write
mov ebx, stdout
mov ecx, msg4
mov edx, msg4len
int 80h
mov eax, sys_read
mov ebx, stdin
mov ecx, code
mov edx, len
int 80h
movzx eax, byte [code]
mov byte [zero], 49
cmp al, byte [zero]
je soma
soma:
mov ebx, dword [nr1]
mov ecx, dword [nr2]
add ebx, ecx
jmp exit
exit:
push ebx
push formatout
call printf
mov eax, sys_exit
mov ebx, stdin
int 80h