Design a simple assembly language instruction set that satisfies the following requirements:
Part 2: Documentation
|
Instruction Syntax
|
Sample
|
Description
|
| ADD reg-d, reg-s |
add R2,R3 |
Add register-s to register-d |
| ADI reg-d, imm8 |
adi R4,0x25 |
Add 8-bit immediate value to register-d |
| AND reg-d, reg-s |
and R4,R2 |
Perform bitwise AND of all bits in register-s on all bits in register-d |
| CMP reg-d, reg-s |
cmp R1,R2 |
Perform an implied subtraction of register-s from register-d, affecting the Zero and Carry flags |
| DIV reg-d, reg-s |
div R6,R4 |
Divide register-d by register-s |
| Jcond label |
cmp R1,R2 jne L2 |
Execute a conditional jump to a label. Possible values for cond are: Z, NZ, E, NE, B, A, AE, BE, C, and NC. The maximum range for the jump is -128 bytes to +127 bytes from the location of the next instruction. |
| JMP label |
jmp L2 |
Unconditional jump to a code label |
| LDA mem |
.data myWord WORD ? .code lda myWord |
Load address of memory operand into accumulator |
| LOD mem |
.data myWord WORD ? .code lod myWord |
Load contents of memory operand into accumulator |
| MOV reg-d, reg-s |
mov R2,R1 |
Copy contents of register-s to register-d |
| MUL reg-d, reg-s |
mul R1,R2 |
Multiply register-d by register-s |
| MVI reg,imm8 |
mvi R2,0x25 |
Move immediate value to register |
| NOT reg |
not R5 |
Invert all the bits in a register (bitwise NOT) |
| OR reg-d, reg-s |
or R4,R2 |
Perform bitwise OR of all bits in register-s on all bits in register-d |
| SBI reg-d, imm8 |
sbi R4,36 |
Subtract 8-bit immediate value from register-d |
| SHL reg-d, reg-s |
shl R4,R2 |
Logically shift register-d left by n bits, where register-s contains n |
| SHR reg-d, reg-s |
shr R4,R7 |
Logically shift register-d right by n bits, where register-s contains n |
| STO mem |
sto myWord |
Store accumulator to memory |
| SUB reg-d, reg-s |
sub R5,R2 |
Subtract register-s from register-d |
| XOR reg-d, reg-s |
xor R4,R2 |
Perform bitwise exclusive-OR of all bits in register-s on all bits in register-d |
|
|
Write a program using your new instruction set that calculates the sum of an array of fifty 16-bit integers and stores the sum in a variable. Use the following declarations, which we assume that your assembler recognizes:
COUNT = 50 .data array WORD COUNT DUP(?) sum WORD ? ; holds the sum .code lda array ; load address of array into accum mov R4,R1 ; store array index in R4 mvi R5,COUNT ; get loop counter mvi R6,0 ; R6 holds the sum L1: lod (R4) ; load word indexed by R4 into accum add R6,R4 ; add word to sum adi R4,2 ; point to next array element sbi R5,1 ; decrement loop counter jnz L1 ; repeat loop if counter != 0 mov R1,R6 ; move sum to accum sto sum ; store accum to sum
Write a program using your new instruction set that compares the contents of three variables named var1, var2, and var3, and moves the largest variabled to the accumulator (R1).
lod var3 mov R5,R1 ; R5 = var3 lod var2 mov R4,R1 ; R4 = var2 lod var1 ; accum = var1 cmp R4,R1 ; var2 > accum? jbe L1 ; no: skip mov R1,R4 ; yes: accum = R4 L1: cmp R5,R1 ; var3 > accum? jbe L2 ; no: skip mov R1,R5 ; yes: accum = R5 L2: ; accum holds largest value
Write a program using your new instruction set that separates the hours, minutes, and seconds fields of a time stamp from a disk directory entry and moves the minutes field into a separate variable. The time format is shown on page 507.
.data timeStamp WORD ? ; starting value minutes WORD ? .code lod timeStamp ; accum = timeStamp mvi R3,5 ; set up shift count shl R1,R3 ; shift accum mvi R3,0x003F ; bit mask for minutes and R1,R3 ; clear unused bits sto minutes ; store in minutes
Write a program using your new instruction set that implements the following expression:
R6 = (var1 + var2) * var3
Do not permit var1, var2, or var3 to be modified. You can assume the following data definitions:
.data var1 WORD ? var2 WORD ? var3 WORD ? .code lod var2 ; accum = var2 mov R2,R1 ; R2 = var2 lod var1 ; accum = var1 add R1,R2 ; accum = left side mov R6,R1 ; R6 = expression in parentheses lod var3 ; accum = var3 mul R6,R1 ; R6 = expression value