Need to write a Assembly language program in nasm to solve the below problem...I wrote 1 but i cannot get the correct output.
.If some one knows Assembly language pls help meeee.....
Problem:
Write an assembly language program that allows entry of a decimal number via the keyboard. Note that the number should be accumulated as a bit word in register eax. The program terminates when a space is entered.
solution:
section .data
accum dd 0 ;This is a double word (32 bits)
msg db 'Please enter a Decimal number: '
len equ $ - msg ;length of string
buf dd 0x0d0a30 ;the input buffer
section .text ;program section
global _start ;must be declared for linker (ld)
_start: ;tell linker entry point
rawmode
my_loop: ;notice that loop is a reserve name
; Write banner
mov edx,len ;message length
mov ecx,msg ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
; Read a digit
mov edx,len ;message length
mov ecx,buf ;message to read
mov ebx,0 ;file descriptor (stdin)
mov eax,3 ;system call number (sys_read)
int 0x80 ;call kernel
mov eax,[buf]
and ax,7fh ;Strip off the most significant bit
cmp ax,0x20 ;Compare with space
je exit ;Jump to exit if space
sub ax, '0' ; Subtract away the ASCII value for '0'
mov edx,15 ;message length
mov [buf],ax ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
xor eax,eax
jmp my_loop ;jump to my_start if sum less twenty
exit:
normalmode
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
.If some one knows Assembly language pls help meeee.....
Problem:
Write an assembly language program that allows entry of a decimal number via the keyboard. Note that the number should be accumulated as a bit word in register eax. The program terminates when a space is entered.
solution:
section .data
accum dd 0 ;This is a double word (32 bits)
msg db 'Please enter a Decimal number: '
len equ $ - msg ;length of string
buf dd 0x0d0a30 ;the input buffer
section .text ;program section
global _start ;must be declared for linker (ld)
_start: ;tell linker entry point
rawmode
my_loop: ;notice that loop is a reserve name
; Write banner
mov edx,len ;message length
mov ecx,msg ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
; Read a digit
mov edx,len ;message length
mov ecx,buf ;message to read
mov ebx,0 ;file descriptor (stdin)
mov eax,3 ;system call number (sys_read)
int 0x80 ;call kernel
mov eax,[buf]
and ax,7fh ;Strip off the most significant bit
cmp ax,0x20 ;Compare with space
je exit ;Jump to exit if space
sub ax, '0' ; Subtract away the ASCII value for '0'
mov edx,15 ;message length
mov [buf],ax ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
xor eax,eax
jmp my_loop ;jump to my_start if sum less twenty
exit:
normalmode
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel









