linux - Division in assembly program -
linux - Division in assembly program -
this code :
section .bss ;uninitialized info average resb 5 num1 resb 5 num2 resb 5 num3 resb 5 section .text global _start ; create main function externally visible _start: ;user prompt mov eax, 4 mov ebx, 1 mov ecx, messaging mov edx, lenmessaging int 0x80 ;read , store user input mov eax, 3 mov ebx, 0 mov ecx, num1 mov edx, 5 ;5 bytes (numeric, 1 sign) of info int 0x80 mov eax, 4 mov ebx, 1 mov ecx, messaging mov edx, lenmessaging int 0x80 ;read , store user input mov eax, 3 mov ebx, 0 mov ecx, num2 mov edx, 5 ;5 bytes (numeric, 1 sign) of info int 0x80 mov eax, 4 mov ebx, 1 mov ecx, usermsg mov edx, lenusermsg int 0x80 ;read , store user input mov eax, 3 mov ebx, 0 mov ecx, num3 mov edx, 5 ;5 bytes (numeric, 1 sign) of info int 0x80 ;output message mov eax, 4 mov ebx, 1 mov ecx, dispmsg mov edx, lendispmsg int 0x80 ; moving first number eax register , sec number ebx ; , subtracting ascii '0' convert decimal number mov eax, [num1] sub eax, '0' mov ebx, [num2] sub ebx, '0' ; add together eax , ebx add together eax, ebx mov ebx, [num3] sub ebx, '0' add together eax, ebx mov bl, '3' sub bl, '0' div bl add together eax, '0' mov [average], eax ;output number entered mov eax, 4 mov ebx, 1 mov ecx, average mov edx, 5 int 0x80 ;//////////////// mov eax, 0x1 ; scheme phone call number exit sub esp, 4 ; os x (and bsd) scheme calls needs "extra space" on stack int 0x80 ; create scheme phone call section .data ;data segment usermsg db 'please come in number: ' ;ask user come in nu lenusermsg equ $-usermsg ;the length of message dispmsg db 'the average : ' lendispmsg equ $-dispmsg messaging db 'enter number : ' lenmessaging equ $-messaging
when run ,i have error :
how can prepare it? programme calculating average of 3 numbers. ;)
int 0x80 / 03h
stores inputted characters and in cases line feed character (0ah). example, num1 gets values 01, 0a, 00, 00, 00
. mov eax, [num1]
gets first 4 bytes, i.e. 00000a01h. ax
holds value 0x1e06 (7686d) before division. div bl
means: ax/bl=al remainder ah. if result of partition doesn't fit al
-register, you'll #de
-exception ("divide error"). 7686/3=2562, 2562 doesn't fit al
, - error. have substantially alter code.
linux assembly nasm division
Comments
Post a Comment