Hi, I need to write a program in the LC-3 assembly language to convert hex to dec. Here are the exact guidelines:
"Your program begins at x3000. Beginning at x4000 is a list of any length of positive numbers, terminated with a -1. Your program must display each number in the list in its decimal value. The numbers should be displayed as you would normally write them, with leading zeroes suppressed. Then halt." Heres what I have so far, my main problem is the actual conversion.

.orig x3000

and r0,r0,#0 ; clear all registers
and r1,r1,#0
and r2,r2,#0
and r3,r3,#0
and r4,r4,#0
and r5,r5,#0
and r6,r6,#0

ld r3,hex ; point to the character string
loop ldr r0,r3,#0 ; load the character
add r1,r0,#1
brz end ; see if we have xFFFF (means done)
trap x21 ; print the character
add r3,r3,#1 ; increment the address pointer
brnzp loop

end trap x25


hex .fill x4000
.end


If anyone can help even in the least I would really appreciate it.

Thanks for your time in looking at this,
Aaron

**Update**
I have spent the entire day working on this probelm now and it works except for even numbers after the first digit (ex: x2435). The first digit can be found correctly and also odd digits but any even digits will mess the output up. If anyone knows what i'm forgetting please let me know. THANKS

THE PROGRAM IS BELOW :

.orig x3000

and r0,r0,#0 ; clear all registers
and r1,r1,#0
and r2,r2,#0
and r3,r3,#0
and r4,r4,#0
and r5,r5,#0
and r6,r6,#0

ld r5,hex ; point to the character string
startover add r5,r5,#1
and r4,r4,#0
ldr r0,r5,#0 ; load the character
add r1,r0,#1
brz end ; see if we have xFFFF (means done)
and r1,r1,#0 ;clear R1 now, using it later

ld r1,frstdig ;finding first digit of hex
not r1,r1 ;start subtraction (for divide)
add r3,r0,r1
add r3,r3,#1
brn print1
add r4,r4,#1
add r2,r1,r3
add r2,r2,#1
brn print1
add r4,r4,#1
add r3,r2,r1
add r3,r3,#1
brn print1
add r4,r4,#1
add r2,r3,r1
add r2,r2,#1
brn print1
add r4,r4,#1
add r3,r2,r1
add r3,r3,#1
brn print1
add r4,r4,#1
add r2,r3,r1
add r2,r2,#1
brn print1
add r4,r4,#1
add r3,r2,r1
add r3,r3,#1
brn print1
add r4,r4,#1
add r2,r3,r1
add r2,r2,#1
brn print1
add r4,r4,#1
add r3,r2,r1
add r3,r3,#1
brn print1


and r4,r4,#0
print1 add r0,r4,#0
add r1,r0,#15
add r0,r1,#15
add r1,r0,#15
add r0,r1,#3
trap x21

and r4,r4,#0
;find value of 2nd hex
ld r1,scndig ;load 2^8
not r1,r1 ;start subtraction (for divide)
add r3,r3,r1
add r3,r3,#1
brn print2
add r4,r4,#1
add r2,r1,r3
add r2,r2,#1
brn print2
add r4,r4,#1
add r3,r2,r1
add r3,r3,#1
brn print2
add r4,r4,#1
add r2,r3,r1
add r2,r2,#1
brn print2
add r4,r4,#1
add r3,r2,r1
add r3,r3,#1
brn print2
add r4,r4,#1
add r2,r3,r1
add r2,r2,#1
brn print2
add r4,r4,#1
add r3,r2,r1
add r3,r3,#1
brn print2
add r4,r4,#1
add r2,r3,r1
add r2,r2,#1
brn print2
add r4,r4,#1
add r3,r2,r1
add r3,r3,#1
brn print2

print2 add r0,r4,#0
add r1,r0,#15
add r0,r1,#15
add r1,r0,#15
add r0,r1,#3
trap x21

and r4,r4,#0
;find value of 3rd hex
ld r1,thrdig ;load 2^4
not r1,r1 ;start subtraction (for divide)
add r3,r3,r1
add r3,r3,#1
brn print3
add r4,r4,#1
add r2,r1,r3
add r2,r2,#1
brn print3
add r4,r4,#1
add r3,r2,r1
add r3,r3,#1
brn print3
add r4,r4,#1
add r2,r3,r1
add r2,r2,#1
brn print3
add r4,r4,#1
add r3,r2,r1
add r3,r3,#1
brn print3
add r4,r4,#1
add r2,r3,r1
add r2,r2,#1
brn print3
add r4,r4,#1
add r3,r2,r1
add r3,r3,#1
brn print3
add r4,r4,#1
add r2,r3,r1
add r2,r2,#1
brn print3
add r4,r4,#1
add r3,r2,r1
add r3,r3,#1
brn print3

print3 add r0,r4,#0
add r1,r0,#15
add r0,r1,#15
add r1,r0,#15
add r0,r1,#3
trap x21

and r4,r4,#0
;find value of 4th hex
ld r1,frthdig ;load 2^0
not r1,r1 ;start subtraction (for divide)
add r3,r3,r1
add r3,r3,#1
brn print4
add r4,r4,#1
add r2,r1,r3
add r2,r2,#1
brn print4
add r4,r4,#1
add r3,r2,r1
add r3,r3,#1
brn print4
add r4,r4,#1
add r2,r3,r1
add r2,r2,#1
brn print4
add r4,r4,#1
add r3,r2,r1
add r3,r3,#1
brn print4
add r4,r4,#1
add r2,r3,r1
add r2,r2,#1
brn print4
add r4,r4,#1
add r3,r2,r1
add r3,r3,#1
brn print4
add r4,r4,#1
add r2,r3,r1
add r2,r2,#1
brn print4
add r4,r4,#1
add r3,r2,r1
add r3,r3,#1
brn print4

print4 add r0,r4,#0
add r1,r0,#15
add r0,r1,#15
add r1,r0,#15
add r0,r1,#3
trap x21
and r0,r0,#0
add r0,r0,#13
trap x21
brnzp startover

end trap x25

hex .fill x3FFF
frstdig .fill x1000
scndig .fill x0100
thrdig .fill x0010
frthdig .fill x0001
.end

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.