Answer the question
In order to leave comments, you need to log in
I don't understand what happens inside the register after the DIV. "Registers break"?
There is a small code for NASM, in which some operations are performed on the input variables: (x + 1) / y.
The problem is that after division, an attempt to deduce the value of the quotient / remainder from the register ends with the output of a goat.
I don't understand why it behaves this way even for simple values (x,y = 3.2). Actually, this is the point, so that it works at least for such small values.
SYS_EXIT equ 1
SYS_READ equ 3
SYS_WRITE equ 4
STDIN equ 0
STDOUT equ 1
section .data
inp1msg db "enter x:", 0xA,0xD
len1 equ $- inp1msg
inp2msg db "enter y:", 0xA,0xD
len2 equ $- inp2msg
outmsg db "result:"
len3 equ $- outmsg
section .bss
x resb 8
y resb 8
z resb 8
section .text
global _start
_start:
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, inp1msg
mov edx, len1
int 0x80
mov eax, SYS_READ ;вводим x
mov ebx, STDIN
mov ecx, x
mov edx, 8
int 0x80
mov eax, SYS_WRITE;вводим у
mov ebx, STDOUT
mov ecx, inp2msg
mov edx, len2
int 0x80
mov eax, SYS_READ
mov ebx, STDIN
mov ecx, y
mov edx, 8
int 0x80
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, outmsg
mov edx, len3
int 0x80
;перемещаем переменные x y в ax bx соответственно
mov ax, [x]
mov bx, [y]
;1 x+1 (увеличиваем x на 1)
inc ax
;2 (x+1)/y делим на у, все проблемы начинаются отсюда
div bx
mov [z], ax
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, z
mov edx, 1
int 0x80
exit:
mov eax, SYS_EXIT
xor ebx, ebx
int 0x80
enter x:
3
enter y:
2
result:�
enter x:
3
enter y:
2
result:4
enter x:
3
enter y:
2
result:�
enter x:
3
enter y:
2
result:
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question