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
brz end ; see if we have xFFFF (means done)
trap x21 ; print the character
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
and r4,r4,#0
ldr r0,r5,#0 ; load the character
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)
brn print1
brn print1
brn print1
brn print1
brn print1
brn print1
brn print1
brn print1
brn print1

and r4,r4,#0
trap x21

and r4,r4,#0
;find value of 2nd hex
not r1,r1 ;start subtraction (for divide)
brn print2
brn print2
brn print2
brn print2
brn print2
brn print2
brn print2
brn print2
brn print2

trap x21

and r4,r4,#0
;find value of 3rd hex
not r1,r1 ;start subtraction (for divide)
brn print3
brn print3
brn print3
brn print3
brn print3
brn print3
brn print3
brn print3
brn print3

trap x21

and r4,r4,#0
;find value of 4th hex
not r1,r1 ;start subtraction (for divide)
brn print4
brn print4
brn print4
brn print4
brn print4
brn print4
brn print4
brn print4
brn print4

trap x21
and r0,r0,#0
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.