Due: Friday, October 11, 2024, 11:00 am (start of the class)
Email Ying your homework. The email subject should follow this format CS232 Fall2024 HW4 -- Your Name.
Given the extended Count circuit below, assume RA and RB are four bits. Write an assembly program by using the mnemonics, LOAD, ADD, NOT, XOR, BRZ, BRA for the following questions. Then translate each assembly program (a program uses the mnemonics) into machine instructions (binary sequences).
The explanation of each mnemonic is listed below.
- LOAD X Y: transfer Y’s value to X. E.g., LOAD RB 0 means RB <= 0
- ADD X Y Z: add the values of X and Y and store the result at Z. E.g., ADD RA RB RB means RB <= RA + RB
- NOT X Y: negate the X’s value and store the result at Y. E.g., NOT RA RA means RA <= not RA
- XOR X Y Z: xor the values of X and Y and store the result at Z. E.g., XOR RA RB RA means RA <= RA xor RB
- BRZ X: conditional branch, branch to line X if the ALU result was zero. E.g., BRZ 3 means if ALU’s result was zero, jump to line 3.
- BRA X: unconditional branch, branch to line X. E.g., BRA 2 jump to line 2.
Some examples for translating assembly program into machine instructions.
- LOAD RB 0 is translated into 0010011dddd (J1J0=00 S1S0=10 C1C0=01 O0=1 D3-D0=dddd) ‘d’ means the value doesn’t matter.
- ADD RA RB RB is translated into 0000001dddd (J1J0=00 S1S0=00 C1C0=00 O0=1 D3-D0=dddd)
- NOT RA RA is translated into 00dd100dddd (J1J0=00 S1S0=dd C1C0=10 O0=0 D3-D0=dddd) When C1C0 = 10 executing NOT A, it negates the value at input A. The value at input B of ALU doesn’t matter. NOT is a unary operation. So the values of S1S0 don’t matter.
- XOR RA RB RA is translated into 0000110dddd (J1J0=00 S1S0=00 C1C0=11 O0=0 D3-D0=dddd)
- BRZ 3 is translated into 10ddddd0011 (J1J0=10 S1S0=dd C1C0=dd O0=d D3-D0=0011)
- BRA 2 is translated into 11ddddd0010 (J1J0=11 S1S0=dd C1C0=dd O0=d D3-D0=0010)
Questions for you to implement:
Subtract RA from RB and put the result in RA. Use whatever values stored in RA and RB for this computation. Don’t need to initialize RA and RB. Do not modify RB. Hint: this count does not have subtraction. But B - A is the same as B + (-A).
Adds the numbers 7, 6, 5, 4, 3, and put the result in RA after the loop terminates. Hint: The loop is terminated when RA is 3. Since the conditional branching can branch only if the ALU result is 0, so, in each iteration, we can decrement RA by 3. If the result is 0, then break out of the loop; Otherwise, add 2 to the result, which will make RA decrement by 1 each time.
© 2024 Ying Li. Page last modified:
.