I strongly recommend against looking at the answers for the problems below until you have attempted the problems. (That's why I put the answers on separate web pages.) There is no need to print the answers out now; they'll be here when you come back, at least through the date of the final exam.
.ORG 1000 | |
MOV X, R2 | |
MUL X, R2 | |
TST R3 | |
BNE OVERFLOW | |
MOV Y, R4 | |
MUL Y, R4 | |
TST R5 | |
BNE OVERFLOW | |
SUB R4, R2 | |
MOV R2, W | |
HALT | |
OVERFLOW: | MOV #0, W |
HALT | |
X: | .WORD 22 |
Y: | .WORD 33 |
W: | .WORD 0 |
(a) Describe simply (in English) what it does (in general, for any values of X and Y).
(b) Assemble the program into unsigned 16-bit octal numbers. (Note that most addressing is relative.)
loc | value |
---|---|
2000 | 016700 |
2002 | 000034 |
2004 | 030027 |
2006 | 000001 |
2010 | 001405 |
2012 | 070027 |
2014 | 000003 |
2016 | 062700 |
2020 | 000001 |
2022 | 000402 |
2024 | 071027 |
2026 | 000002 |
2030 | 020027 |
2032 | 000001 |
2034 | 003363 |
2036 | 000000 |
2040 | 000005 |
(a) Disassemble this program (convert it to assembly language). You needn't introduce labels.
(b) Describe simply what it does, and state the final contents of R0, R1, R7 (the PC), and memory location 2040, assuming that the PC starts at 002000.
Note: The bitwise AND of an integer with 1 discards all but its least significant bit. If this bit is zero, the number is even; else it is odd.
(c) Will the program work correctly if it is loaded at memory location 1000 instead of 2000? If yes, justify briefly; if no, explain why not.
(a) Describe simply (in English) what it does.
(b) Assemble the program into unsigned 16-bit octal numbers. (Note that most addressing is relative.)
.ORG 2000 | |
MOV #500, R1 | |
MOV #600, R2 | |
MOV #700, R3 | |
MOV N, R4 | |
JSR R7, ROUTINE | |
HALT | |
ROUTINE: | MOV -(R1), R0 |
SUB (R2)+, R0 | |
MOV R0, (R3)+ | |
DEC R4 | |
BGT ROUTINE | |
RTS R7 | |
N: | .WORD 40 |
answer to problem #3 DON'T LOOK AT MY ANSWER UNTIL YOU'VE TRIED IT YOURSELF!
loc | value |
---|---|
2000 | 005000 |
2002 | 005001 |
2004 | 066701 |
2006 | 000020 |
2010 | 005200 |
2012 | 020067 |
2014 | 000010 |
2016 | 002772 |
2020 | 010167 |
2022 | 000006 |
2024 | 000000 |
2026 | 000005 |
2030 | 000006 |
2032 | 000007 |
(a) Disassemble this program (convert it to assembly language). You needn't introduce labels.
(b) Describe simply what it does, and state the final contents of R0, R1, R7 (the PC), and memory locations 2026, 2030, and 2032, assuming an initial contents of [R7]=002000, [R0]=000055, [R1]=177002.
Suppose that you were sceptical of this formula and no one showed you a proof. You try it for a few cases and it works, but you are having difficulty finding a proof yourself. Before looking harder for a proof you'd like to verify it for a few hundred cases or more, by computer.
Write a subroutine in PDP-11 assembly language which verifies this equation (i.e. that the two sides are indeed equal), for 0 <= n < N. It will be called as follows (or equivalent):
MOV #N, R0 JSR R7, ROUTINEIf overflow occurs at any point in your calculation, your subroutine should return with the overflow condition code set. Otherwise, if it finds a counterexample to this formula, it should return with the n counterexample in R0 and with carry set (and overflow clear). If it verifies the formula for all n, 0 <= n < N, it will return with carry and overflow both clear (and R0 can be anything).
Your program needn't be especially well-commented but you should explain your use of registers and anything else particularly unclear. Do not assemble your code; leave it in symbolic form.
MOV #1, R0 ADD R0, (R7)+ ADD R0, (R7)+ ADD (R7)+, R0 ADD R0, (R7)+ NOP HALTYour answer should include an initial layout of memory, a final layout of memory, and final values of R0 and R7.
loc | value |
---|---|
160 | 012700 |
162 | 000030 |
164 | 062717 |
166 | 100000 |
170 | 062700 |
172 | 000020 |
174 | 000000 |
(a) Disassemble this program (convert it to assembly language). You needn't introduce labels.
(b) Trace its execution and explain what happens. State the final contents of R0 and R7.
MOV #3000, -(R6) MOV #20, -(R6) JSR R7, ROUTINE ADD #4, R6You return the computed sum in R0. Your subroutine may thus use R0 as a scratch register, but any other registers used must be pushed and restored.
Your subroutine is required to check for overflow. If none of the addition operations overflows, your subroutine must return the sum in R0, and with the V condition code clear. If any of the addition operations overflow, your subroutine must return with the V condition code set, and in that case it doesn't matter what the final contents of R0 is. In the case of overflow, the caller will ignore the returned contents of R0; thus your subroutine may return immediately. (So there would actually be a BVS instruction between the JSR and the ADD in the calling sequence above.)
You need not handle the case of zero-sized arrays; the count (second argument) must be positive. You are not required to handle any kind of incorrect use of your subroutine.
Your program needn't be especially well-commented but you should explain your use of registers and anything else particularly unclear.
Do not assemble your code; leave it in symbolic form.
You are assisting a group with a large body of code for older PDP-11s. These older PDP-11s did not have a DIV op, so they used an EMT. The group's programs contain the op 104112, which is to have the semantics R0 <- [R0] div M (integer quotient). The value M is contained in the following word of the program (as an immediate operand), which the EMT must skip upon return.
This group now has a newer PDP-11 which does have a DIV op. Their existing EMT will work, but it contains a software integer division routine which is not as fast as a DIV op. Your task is to write a new EMT routine which simply does the DIV. (They will be using a DIV directly in all new code, but they have a large body of existing code which they want to speed up, too.)
For simplicity, assume that there are no other EMT routines in operation, and that you needn't check that they used the correct opcode. If you get an EMT trap, it's this fake division op.
Your answer will have to set the trap vector as well as provide the code for the routine. Don't forget to save registers as appropriate; don't forget that the hardware DIV yields a two-word result (even though you don't care about the second word, it better not erase anything); and don't forget to skip the M value's word upon return.