CS 1104 Computer Systems Assignment 6

Written Assignment 6

CS 1104: Computer Systems

Unit 6: Machine Language

For the Unit 6 assignment, hand compile the following two assembly language programs into machine language that can be loaded into an executed on the Hack computer.

Chapter 4 of the Nisan and Schocken text describes the machine language instructions that are supported by the Hack computer system. It is important to understand that different computer architectures will support different capabilities and of course this translates into differences in both the machine language instructions of the computer and the assembler language that supports the system.

In the Hack computer platform, there are essentially two types of machine language instructions the A instruction (see below)

And the C instruction as follows.  ALL Hack computer programs can be developed using these two instructions.

The C instruction allows the programmer to interact with the CPU (and, in particular, the ALU) to perform computations against the values in the registers.  If you recall, in Unit 2 we presented the ALU for the Hack computer as follows:

Each of the instructions that the Hack ALU is capable of running can be specified to the ALU through a set of control bits. These control bits or the C bits in the instruction and their associated functions are listed below.

IT IS IMPORTANT TO COMPLETE THIS EXERCISE. I caution you not to take any shortcuts. The best way to really gain an understanding of how machine language and assembler language works is by learning how to convert assembler into machine language. We will gain an understanding of the relationship between hardware and software in this process. As such I urge you to NOT be tempted to cheat and use a compiler for this task.

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

  • @2 converted to binary is 0000 0000 0000 0010.
  • D=A refers to the address location from previously, which is @2, so D = 0000 0000 0000 0010.
  • @3 converted to binary is 0000 0000 0000 0011.
  • D=D+A refers to itself add A. A at address location from previously is @3, which is 0000 0000 0000 0011, add the D value assigned to it from previously, which was @2 (0000 0000 0000 0010). The sum of D and A is 5, which is 0000 0000 0000 0101.
  • @0 is 0000 0000 0000 0000.
  • M=D, which means Memory[0] (using @0) is equal to D, which means Memory[0] location is 5, which is 0000 0000 0000 0111.
  • Therefore, the final result is that the Memory[0] location is equal to 5, which is 0000 0000 0000 0111 in binary.
  • Hence, the conversion for program 1 to binary is the following:
    • @2 \\ 0000000000000010
    • D=A \\ 0000000000000010
    • @3 \\ 0000000000000011
    • D=D+A \\ 0000000000000111
    • @0 \\ 0000000000000000
    • M=D \\ 0000000000000101

// 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

  • @0 converted to binary is 0000 0000 0000 0000.
  • D=M refers to the address location from previously, which is@0, is equal to Memory[0] location. Currently set to 0 since nothing is there.
  • @1 converted to binary is 0000 0000 0000 0001, so address is at 1.
  • D=D-M, since still set to 0, D is still 0.
  • If D is greater than 0 based on code JGT and D @1 is equal to memory[1], go to 10, else go to 12, else go to 14. Since @10, address is set to 10. M/A input is then 10 because A is 10.
  • @1, address is set to 1, and Memory set to 1.
  • @12, address set to 12, so M/A input is 12.
  • @2 address is set to 2, so when M=D, M/A input set to 2.
  • @14, address set to 14, so M/A input set to 14.
  • Hence, the binary conversion of each of the steps is the following:
    • @0 \\ 0000000000000000
    • D=M \\ 1111110000010000
    • @1 \\ 0000000000000001
    • D=D-M \\ 1111010011010000
    • @10 \\ 0000000000001010
    • D;JGT \\ 1110001100000001
    • @1 \\ 0000000000000001
    • D=M \\ 1111110000010000
    • @12 \\ 0000000000001100
    • 0;JMP \\ 1110101010000111
    • @0 \\ 0000000000000000
    • D=M   \\ 1111110000010000
    • @2 \\ 0000000000000010
    • M=D \\ 1110001100001000
    • @14 \\ 0000000000001110
    • 0;JMP \\ 1110101010000111

Please see attached .asm files for original problem and .hack files for binary conversions of each respective program.

References

Nissan, N., Schocken, S. (2005). The Elements of Computing Systems, Chapter 4: Machine Language.

Want latest solution of this assignment
AssignmentHippo Features
  • On Time Delivery

    Our motto is deliver assignment on Time. Our Expert writers deliver quality assignments to the students.

  • Plagiarism Free Work

    Get reliable and unique assignments by using our 100% plagiarism-free services.

  • 24 X 7 Live Help

    The experienced team of AssignmentHippo has got your back 24*7. Get connected with our Live Chat support executives to receive instant solutions for your assignment problems.

  • Services For All Subjects

    We can build quality assignments in the subjects you're passionate about. Be it Programming, Engineering, Accounting, Finance and Literature or Law and Marketing we have an expert writer for all.

  • Best Price Guarantee

    Get premium service at a pocket-friendly rate. At AssignmentHippo, we understand the tight budget of students and thus offer our services at highly affordable prices.