Question: LC 3 PROGRAMMING ASSEMBLY LANGUAGE Write an LC - 3 assembler program that converts a number stored in memory into its binary representation in the

LC3 PROGRAMMING ASSEMBLY LANGUAGE Write an LC-3 assembler program that converts a number stored in memory into its binary
representation in the Minecraft world.
a) Place your code in the assembly file "write_binary.asm".
b) The number to convert is specified in the LC-3 starter file as NUMBER_TO_CONVERT.
c) You can assume that the number to convert will always be non-negative.
d) Use air (block ID #0) to represent zeroes and stone blocks (block ID #1) to represent 1s.
i) The least significant bit should be written to (playerPos.x, playerPos.y, playerPos.z+1).
ii) The next bit should be written to (playerPos.x, playerPos.y, playerPos.z+2) and so on
(see Figure 1 for a visual explanation).
iii) Since the word size in LC-3 is 16 bits, your program should always output 16 blocks,
writing extra zeroes as air blocks if necessary.
Figure 1: Illustration of how to output the binary representation in Minecraft. The number
represented here is 237=0000000011101101. The least significant bit is closest to the player.
.ORIG x3000
; Get player's current position
TRAP x29 ; Get tile position (R0= x, R1= y, R2= z)
ADD R2, R2, #1 ; Start at z+1(move placement one block forward)
LD R6, NUMBER_TO_CONVERT ; Load the number to convert (237 in binary: 0000000011101101)
LD R4, BIT_COUNT ; Set loop counter to 16(for 16 bits in binary representation)
; Store player's x and y coordinates
ST R0, PLAYER_X
ST R1, PLAYER_Y
; Loop to process all 16 bits
CONVERT_LOOP
; Check if the least significant bit (LSB) is 1 or 0
AND R3, R6, #1 ; Mask the LSB (check if it's 1)
BRz CALL_AIR ; If the bit is 0, branch to CALL_AIR (place air block)
; If the bit is 1, call the subroutine to place stone
JSR PLACE_STONE
BR NEXT_BIT
CALL_AIR
JSR PLACE_AIR ; Call subroutine to place air block
NEXT_BIT
ADD R2, R2, #1 ; Increment the z-coordinate for the next block
ADD R4, R4, #-1 ; Decrement bit counter
BRz END_CONVERSION ; If all bits are processed, end
; Shift number to the right by 1 bit to check the next bit
ADD R6, R6, R6 ; Logical shift right (move to the next bit)
ADD R6, R6, #0 ; This is just a filler to prevent errors, as LSR cannot be used.
ADD R6, R6, R6 ; Shift right by adding R6 to itself and discarding the result in the upper half
BR CONVERT_LOOP
; Subroutine to place a stone block
PLACE_STONE
LD R3, STONE_BLOCK ; Load stone block ID into R3
LD R0, PLAYER_X ; Load player's x coordinate into R0
LD R1, PLAYER_Y ; Load player's y coordinate into R1
TRAP 0x2C ; Use setBlock (0x2C) to place the stone block at (R0, R1, R2)
RET ; Return from subroutine
; Subroutine to place an air block
PLACE_AIR
LD R3, AIR_BLOCK ; Load air block ID into R3
LD R0, PLAYER_X ; Load player's x coordinate into R0
LD R1, PLAYER_Y ; Load player's y coordinate into R1
TRAP 0x2C ; Use setBlock (0x2C) to place air block at (R0, R1, R2)
RET ; Return from subroutine
END_CONVERSION
HALT ; End of program
; Data section
NUMBER_TO_CONVERT .FILL #237 ; The number 237 in binary: 0000000011101101
BIT_COUNT .FILL #16 ; 16 bits to process
STONE_BLOCK .FILL #1 ; Stone block ID (1)
AIR_BLOCK .FILL #0 ; Air block ID (0)
PLAYER_X .BLKW #1 ; Reserve space to store player's x-coordinate
PLAYER_Y .BLKW #1 ; Reserve space to store player's y-coordinate
.END
currently my code places stone then the rest is air
i want it to place stone air stone stone air stone stone stone then rest air
please fix it
LC 3 PROGRAMMING ASSEMBLY LANGUAGE Write an LC -

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 Programming Questions!