Class notes from week of April 2-5 -------------------------------------------------------------------------------------- CPU Registers R accumulator PC program counter IR instruction register MAR memory address register MDR memory data register CCR comparison flags ALU1 ALU operand 1 ALU2 ALU operand 2 Go over the function of each register. -------------------------------------------------------------------------------------- Assembly Language Instructions opcode mneumonic meaning 0000 LOAD X load contents of location X into accumulator register R 0001 STORE X store contents of accumulator register R in location X 0010 CLEAR X store 0 in location X 0011 ADD X add contents of location X to accumulator register R 0100 INCREMENT X add 1 to contents of location X 0101 SUBTRACT X subtract contents of location X from accumulator register R 0110 DECREMENT X subtract 1 from contents of location X 0111 COMPARE X compare contents of location X to accumulator register R if contents(X) > R, set GT bit to 1 else 0 if contents(X) < R, set LT bit to 1 else 0 if contents(X) = R, set EQ bit to 1 else 0 1000 JUMP X store address X in program counter register PC 1001 JUMPGT X if GT bit = 1, store address X in program counter register PC 1010 JUMPEQ X if EQ bit = 1, store address X in program counter register PC 1011 JUMPLT X if LT bit = 1, store address X in program counter register PC 1100 JUMPNEQ X if EQ bit = 0, store address X in program counter register PC 1101 IN X input an integer value and store it in location X 1110 OUT X output the contents of location X 1111 HALT stop program execution Pseudo-ops: .begin LABEL: instruction LABEL: .data value .end ------------------------------------------------------------------------------------- Translate into assembly code (a) Add 1 to the value of x INCREMENT X (b) Add 50 to the value of x LOAD X ADD FIFTY STORE X HALT FIFTY: .data 50 (c) Set x to the value y+z-2 LOAD Y ADD Z SUBTRACT TWO STORE X HALT TWO: .data 2 (d) If x > 50 then output the value of x, otherwise input a new value of x LOAD FIFTY COMPARE X JUMPGT YES IN X HALT YES: OUT X HALT ------------------------------------------------------------------------------------- Example: a program to count from 1 to 10 Pseudocode: set COUNT to 1 while COUNT <= 10 do (or equivalently: if COUNT > 10 quit loop) output COUNT set COUNT to COUNT+1 (end of loop) Assembly code: Address Instruction .begin 0 LOAD ONE 1 STORE COUNT 2 LOOP: LOAD TEN 3 COMPARE COUNT 4 JUMPGT DONE 5 OUT COUNT 6 INCREMENT COUNT 7 JUMP LOOP 8 DONE: HALT 9 COUNT: .data 0 10 ONE: .data 1 11 TEN: .data 10 .end Symbol table: Data label Address COUNT 000000001001 (9) ONE 000000001010 (10) TEN 000000001011 (11) Instruction label Address LOOP 000000000010 (2) DONE 000000001000 (8) Object code: 0000000000001010 0001000000001001 0000000000001011 0111000000001001 1001000000001000 1110000000001001 0100000000001001 1000000000000010 1111000000000000 0000000000000000 0000000000000001 0000000000001010