aunabidi
10-23-2005, 11:59 PM
Hi. I am doing a project in which I have to convert decimal to binary in assembly language. The program should repeatedly prompt the user for an input and display the input in binary until the user chooses to quit. The binary representation should only show one leading zero. I am not good at all with assembly so please help me out with this problem that I am having. I wrote the program layout and it does everything but the conversion. I have an idea how to do it but I cant put it down in code. The conversion part is in the divloop. Here is my program:
.section ".data"
prompt: .asciz "Please enter a number: "
format: .asciz "%d"
output: .asciz "You entered: %d\n"
binary: .asciz "In binary it is: "
new: .asciz "\n"
ask: .asciz "Do you want to continue? (y/n) "
value: .asciz "%c"
.align 4
.section ".text"
.global main
main: save %sp, -96, %sp
loop:
set prompt, %o0
call printf
nop
set format, %o0
add %fp,-4,%o1
call scanf
nop
set output, %o0
ld [%o1],%l0
mov %l0,%o1
call printf
nop
set binary,%o0
call printf
nop
set 0x80000000,%l2
mov 32,%l3
divloop:
set format,%o0
and %l0,%l2,%o1
cmp %o1, 0
be else
nop
mov 0,%o2
call printf
nop
nop
set new,%o0
call printf
nop
set value,%o0
add %fp,-4,%o1
call scanf
nop
set ask,%o0
call printf
nop
set value,%o0
add %fp,-4,%o1
call scanf
nop
ldub [%o1],%l0
comp:
cmp %l0,'y'
be loop
nop
else:
mov 1,%o2
call printf
nop
ret
restore
Please ask me if you dont understand it. I would really appreciate it if someone could help me out. Thanks a lot
.section ".data"
prompt: .asciz "Please enter a number: "
format: .asciz "%d"
output: .asciz "You entered: %d\n"
binary: .asciz "In binary it is: "
new: .asciz "\n"
ask: .asciz "Do you want to continue? (y/n) "
value: .asciz "%c"
.align 4
.section ".text"
.global main
main: save %sp, -96, %sp
loop:
set prompt, %o0
call printf
nop
set format, %o0
add %fp,-4,%o1
call scanf
nop
set output, %o0
ld [%o1],%l0
mov %l0,%o1
call printf
nop
set binary,%o0
call printf
nop
set 0x80000000,%l2
mov 32,%l3
divloop:
set format,%o0
and %l0,%l2,%o1
cmp %o1, 0
be else
nop
mov 0,%o2
call printf
nop
nop
set new,%o0
call printf
nop
set value,%o0
add %fp,-4,%o1
call scanf
nop
set ask,%o0
call printf
nop
set value,%o0
add %fp,-4,%o1
call scanf
nop
ldub [%o1],%l0
comp:
cmp %l0,'y'
be loop
nop
else:
mov 1,%o2
call printf
nop
ret
restore
Please ask me if you dont understand it. I would really appreciate it if someone could help me out. Thanks a lot