Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Once you have been able to translate each of the following two programs written

ID: 3838998 • Letter: O

Question

Once you have been able to translate each of the following two programs written in Hack Assembler into binary machine code,   Load your machine language program into the cpu simulator and execute it.

For your assignment post a description of YOUR process to convert the assembler symbols into machine language and what you learned in the process. Also include both your assembler program and corresponding machine language program in your assignment.

//Program 1 to convert to machine language
// Computes R0 = 2 + 3

@2
D=A
@3
D=D+A
@0
M=D

// Program 2 to convert to machine language
// Symbol-less version of the Max.asm program.

@0
D=M
@1
D=D-M
@10
D;JGT
@1
D=M
@12
0;JMP
@0
D=M
@2
M=D
@14
0;JMP

Explanation / Answer

// Multiplicand and multiplier are pre-loaded into R0 and R1

,

// respectively.

mask = 1; // mask is used to isolate a single bit of the

// multiplier.

i = 0;

R2 = 0; // Product accumulated into R2

while (i < 16)

{

// Isolate current multiplier bit; accumulate shifted mult

iplicand

// in R0 into R2 if this bit is set.

if ((mask & R1) != 0)

R2 = R2 + R0;

// Shift intuition: adding a number to itself is equivalent t

o

// multiplying it by 2: x + x = 2x. In binary, multiplying a

// value by two results in all of the bits of the value being

// shifted left one bit position, with a 0 being shifted into

// the lsb position and the msb being lost.

R0 = R0 + R0; // Shift multiplicand left one bit position.

i = i + 1;

mask = mask + mask; // Shift mask left one bit position.

}

sptr = SCREEN; // Memory pointer to next screen memory locati

on

// to be filled with black or white pixels.

clear = true; // This is for the 10 "smooth user experience" po

ints.

// See implementation tip in Proposed Implementation

// Section below.

while (1)

{

if (keyboard != 0) // Fill with black pixels.

{

if (clear) // For "smooth user experience."

{

clear = false;

sptr = SCREEN;

}

*sptr = -1; // Write 16 black pixels to the screen memory locat

ion

// pointed to by sptr.

}

else // Fill with white pixels.

{

if (!clear) // For "smooth user experience."

{

clear = true;

sptr = SCREEN;

}

*sptr = 0; // Write 16 white pixels to the screen memory locatio

n

// pointed to by sptr.

}

sptr = sptr + 1; // Increment sptr to point to next location

// in screen memory.

// If we’ve reached the end of screen memory, start over.

if (sptr >= SCREEN + 8192)

sptr = SCREEN;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote