Question: LC3 program : Exercise 04 The first step will be to output the 1's and 0's of a stored value as 16 ascii characters: But

LC3 program :

Exercise 04 The first step will be to output the 1's and 0's of a stored value as 16 ascii characters: But wait! ... You already did this in your last assignment! I. Make a copy of your assn 3 code and modify it so that it prints out the contents of register 2. II. Now copy your ex3 code into lab05_ex4.asm, and add in your new output code: drop it in after you load the 7th

array value to R2.

At this point your program should print out 2^6 in binary format: b0000 0000 0100 0000

So now we know how to print any number in binary format (put the value in R2 and paste the binary print code); and we also know how to write code that can build and traverse an array. It is time to combine our knowledge to print out all elements in the array!! III. Modify your program so that it prints all the values in the array of powers of 2. i.e.

b0000 0000 0000 0001 b0000 0000 0000 0010 b0000 0000 0000 0100 .... .... b0000 0001 0000 0000 b0000 0010 0000 0000

Keep your code clean and well organized, for example in pseudo-code it should look something like this: ex. 03: Prepare the binary array with successive powers of 2 ex. 04: Load starting address of array into a base register (say R6) for each element in array load the value to R2 print the value in R2 (use 'the code') end of program (HALT) // program data

code to print out 16 ASCII characters of 1 and 0s

.ORIG x3000 ; Program begins here ;------------- ;Instructions ;------------- LD R6, Value_addr ; R6 <-- pointer to value to be displayed as binary LDR R1, R6, #0 ; R1 <-- value to be displayed as binary ;------------------------------- ;INSERT CODE STARTING FROM HERE ;-------------------------------- LD R3, MAX_VAL

AND R5, R5, #0 ADD R5, R5, #15 AND R4, R4, #0 ADD R4, R4, #4

LOOP

ADD R4, R4, #0 BRp PRINT_NEXT

LEA R0, SPACE PUTS AND R4, R4, #0 ADD R4, R4, #4 ADD R5, R5, #0 BRnp PRINT

PRINT_NEXT ADD R1, R1, #0 BRn IFONE LEA R0, ZERO PUTS BRnp ENDPRINTZERO

IFONE LEA R0, ONE PUTS ENDPRINTZERO ADD R1, R1, R1 ADD R5, R5, #-1 ADD R4, R4, #-1 PRINT BRzp LOOP LD R0, NEW_LINE OUT

HALT ;--------------- ;Data ;---------------

NEW_LINE .FILL x000A MAX_VAL .FILL #32768 ZERO .STRINGZ "0" ONE .STRINGZ "1" COUNTER .FILL #16 SPACE .STRINGZ " "

Value_addr .FILL xD800 ; The address where value to be displayed is stored

.ORIG xD800 ; Remote data Value .FILL xABCD ; <----!!!NUMBER TO BE DISPLAYED AS BINARY!!! Note: label is redundant. ;--------------- ;END of PROGRAM ;--------------- .END

code to create array of array with successive values of 2

.orig x3000

LD R3, ITER_COUNTER ;determinung the size of the array being filed/how many iterations for the loop LD R5, DEC_ONE ;the decimal zero LD R4, ARRY_PTR ;assigning the new destination for the pointer LD R6, DEC_48 ;number to add to get character

ARRAY_LOOP ; beginning the loop

STR R5,R4,#0 ;store the value at this iteration into the array ADD R5,R5,R5 ;increment the dec 1 so that R5 will add to itself and increase exponentially as the loop continues ADD R4,R4,#1 ;move onto the next adDress ADD R3,R3,#-1 ;decrement the iterator counter BRp ARRAY_LOOP ;Go through the loop as lng as the iterator is postive

END_ARRY_LOOP

HALT

;-------------------------- ;Data ;--------------------------

ARRY_PTR .FILL x4000 DEC_ONE .FILL #1 ITER_COUNTER .FILL #10 DEC_48 .FILL #48

.orig x4000

NEW_ARRAY .BLKW #10

.END

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!