汇编语言数学函数:

时间:2018-06-14 16:21:24

标签: assembly nasm

出于某种原因,这实际上不会进入我的其他功能,例如减法,除法等。当我在程序中输入我的数字时它会占用它们并打印出我存储在系统中的第一个数字。我可能需要修复我的控制结构吗?这应该是一个简单的计算器,它采用两个数字和一个符号并给出答案。我的另一个问题是在输入两个数字后打印“=”符号的最佳方法是什么。 谢谢,

segment .data

segment .bss
num1: resb 4
num2: resb 4
button: resb 2
segment .text
     global  asm_main

  asm_main:
push    ebp
mov     ebp, esp
; ********** CODE STARTS HERE **********

call read_int
mov DWORD[num1], eax

call read_char
mov DWORD[button], edx
call read_char

call read_int
mov DWORD[num2], ebx

cmp DWORD[button], '+'
je addition

cmp DWORD[button], '-'
je subtraction

cmp DWORD[button], '*'
je multiplication

cmp DWORD[button], '/'
je division

cmp DWORD[button], '%'
jle modulus


addition:
mov eax, DWORD[num1]
add eax, DWORD[num2]

call print_int
call print_nl
jmp end

subtraction:
mov eax, DWORD[num2]
mov eax, DWORD[num1]
call print_int
call print_nl

jmp end
multiplication:
mov eax, DWORD[num1]
mov ebx, DWORD[num2]
mul ebx
call print_int
call print_nl
jmp end

division:
mov eax, DWORD[num1]
mov ebx, DWORD[num2]
mov edx, 0
div edx
jmp end

modulus:
mov eax, DWORD[num1]
mov ebx, DWORD[num2]
call print_int
call print_nl

jmp end

0 个答案:

没有答案