write a LC3 assembly language program to (a) read in a
hexadecimal number, (b) convert the number to a 16-bit binary number, and, (c) display the
16-bit binary number. It should be assumed that (a) the number entered by the user is a valid
unsigned hexadecimal number consisting of at least one hexadecimal digit and at most four
hexadecimal digits, (b) the hexadecimal number is within range [0 .. 0x7FFF], and, (c) the
hexadecimal digits entered by the user come from set {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E,
F}. The example below shows some screenshots of the execution of the program.

And?

Nobody is doing your homework for you here. Post some code, show us what you've done, tell us where you are stuck and then, only then, will we try and help you...

.ORIG   X3000
    LEA R0,SHOW
    PUTS
    LEA R6,SIZE
    LD  R3,LOOP
    AND R1,R1,#0
    AND R5,R5,#0

AA  GETC
    LD  R4,ENTER
    ADD R5,R4,R0
    BRz START   ;IF ENTER JUMP
    OUT

    ADD R1,R1,R1
    ADD R1,R1,R1
    ADD R1,R1,R1    ;SHIFT LEFT 4 TIMES
    ADD R1,R1,R1

    LD  R2,LETTER
    ADD R2,R0,R2

    BRn NU
    LD  R2,MIN
    ADD R2,R0,R2
    ADD R1,R1,R2
    LD  R2,GG
    ADD R2,R2,#1
    BRz START
    ST  R2,GG
    BRnzp   AA



this is where I stuck on. 

Edited 1 Year Ago by Ben_13

I've done one program which prompts user to enter a integer and echo back whats been entered. this one is a advance version which ask for conversion of hex to binary.

    .ORIG   x3000
    LEA R4, ARRAY   ; Display the prompt


    LEA     R0, PROMPT  ; Get the base address of the array
    PUTS

    AND R2, R2, #0
WHILE   GETC            ; Read and echo a character (stored in R0)

    ADD     R2, R2, #1  ; Quit if character = return


    LD  R5,FULL
    ADD R5, R2, R5
    BRz     END


    AND R5, R5, 0
    LD  R5, ENTER
    ADD R5, R0, R5
    BRz     END
    OUT
    STR     R0, R4, #0  ; Store that character in the array
    ADD     R4, R4, #1  ; Increment the address of the array cell
    BRnzp   WHILE             ; Return to read another character

END LEA R0, OUTPUT
    PUTS

    AND R1, R1, #0  ; initialised R2 to 0
    LEA R4, ARRAY       ; 

PRINTOUT LDR    R0, R4, #0  ; load the value of R5 into R0
    ADD R4, R4, #1  ; points R5 to the previous address plus 1
    ADD R1, R1, #1  ; increment to the counter R2


    AND R5, R5, #0  ; initialised R1 to 0
    ADD R5, R1, #0  
    NOT R5, R5
    ADD R5, R5, #1
    ADD R5, R2, R5
    BRz FINISH      ; jump to stop
    OUT

    BRnzp   PRINTOUT    ; end of the output loop

    FINISH  HALT

; Main program data
PROMPT  .STRINGZ    "Please enter a number: "
OUTPUT  .STRINGZ    "\nThe input is:"
ARRAY   .BLKW       20  ; Array of 20 characters (including null)
ENTER   .FILL   #-10
FULL    .FILL   #-21

.END

every hex character is a 4 character binary number
1 = 0001
2 = 0010
9 = 1001
f = 1111
f29 therefore is 111100101001
create an array 1-f as key, 0000 to 1111 as value
match each hex character sequentially , as key, to output the coresponding value

Edited 1 Year Ago by almostbob

And when you get the next homework question, bin > hex, start right to left with 4 characters at a time

This article has been dead for over six months. Start a new discussion instead.