SYS_EXIT equ 1
SYS_READ equ 3
SYS_WRITE equ 4
STDIN equ 0
STDOUT equ 1
segment .data
msg1 db "Enter two digits: ", 0xA,0xD
len1 equ $- msg1
msg2 db "Result: ", 0xA,0xD
len2 equ $- msg2
segment .bss
num1 resb 1
num2 resb 1
res resb 1
segment .text
global _start
_start:
; disp msg
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, msg1
mov edx, len1
int 0x80
; enter num1
mov eax, SYS_READ
mov ebx, STDIN
mov ecx, num1
mov edx, 2
int 0x80
; print num1
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, num1
mov edx, 2
int 0x80
; enter num2
mov eax, SYS_READ
mov ebx, STDIN
mov ecx, num2
mov edx, 2
int 0x80
; print num2
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, num2
mov edx, 2
int 0x80
; move first to eax, second to ebx
mov eax, num1
sub eax, byte '0'
mov ebx, num2
sub ebx, byte '0'
; or them and store the result in eax, and then eax in res
or eax, ebx
add eax, byte '0'
mov [res], eax
; disp result msg
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, msg2
mov edx, len2
int 0x80
; write result
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, res
mov edx, 1
int 0x80
outprog:
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
In the segment of code above, I wish to take two digits as input, or them, and display the result. However, when I compile and run this code, no matter which input I give the program, the program always return the character ]
. I am fairly new to programming in assembly and I am not entirely sure as to why this is happening. I've done a bit of research and found that the ascii values for ]
are (in order dec, hex): 93, 5D, however, I do not know what correlation that character has with the code I have written. Any explanation as to why this is happening and advice as to how to avoid such bugs in the future would be wonderful.
[PROBLEM SOLVED] I had to change
mov eax, num1
tomov eax, [num1]