Hypothetical Machine Simple Decimal Machine Single Accumulator (need not reference it explicitly) Architecture ( = programmer's view) Registers: Accumulator [ | | | | ] 5 decimal digits Program Counter [ | | ] 3 decimal digits Comparison Indicator [ ] states: HIGH, LOW, EQUAL Memory: Each word contains 5 decimal digits: 0 1 2 3 4 [ | | | | ][ | | | | ][ | | | | ][ | | | | ][ | | | | ] 5 6 [ | | | | ][ | | | | ] ... 993 994 ... [ | | | | ][ | | | | ] 995 996 997 998 999 [ | | | | ][ | | | | ][ | | | | ][ | | | | ][ | | | | ] Instruction Format: Each instruction occupies one word and consists of two fields: Operation Code, 2 decimal digits 100 possible op codes Address Field, 3 decimal digits 1000 words of memory (maximum) OP ADDR [ . | . . ] Instruction Set (Table of Op Codes) SMALL SUBSET Mnemonic Code Description HALT 00 Halt the machine LOAD 11 Load accumulator with copy of word addressed STORE 12 Copy accumulator to word addressed ADD 21 Add word addressed to accumulator Simple Program -- Add a few numbers Assume that program starts at memory location 200 Assume that negative data values are represented in 10's complement form. Object Code Equivalent Assembler Source Code Loc Contents Label Oper Argument Comments 200 11207 BEGIN LOAD X 201 21206 ADD Y 202 21205 ADD Z 203 12208 STORE ANS 204 00000 HALT 205 00024 Z DW 24 \ 206 99996 Y DW -4 \ Memory initialization 207 00007 X DW 7 / with data. 208 ????? ANS DW ? / END BEGIN Mark end as specify start Note that instructions like DW and END are not machine instructions, but rather instructions to the Assembler (program) or Pseudo Instructions. The ? indicates that we have no way of knowing (or reason to know) what number will be there. (It will not be a ?, but a digit from 0 to 9.) Program in memory may be thought of as: + 0 1 2 3 4 200 [1.1.2.0.7][2.1.2.0.6][2.1.2.0.5][1.2.2.0.8][0.0.0.0.0] 205 [0.0.0.2.4][9.9.9.9.6][0.0.0.0.7][?.?.?.?.?][?.?.?.?.?] Or more compactly as: 0 1 2 3 4 5 6 7 8 9 190 ????? ????? ????? ????? ????? ????? ????? ????? ????? ????? 200 11207 21206 21205 12208 00000 00024 99996 00007 ????? ????? 210 ????? ????? ????? ????? ????? ????? ????? ????? ????? ????? Instruction Set (Table of Op Codes) ADDITIONAL INSTRUCTIONS Mnemonic Code Description CMP 31 Compare accumulator with word address and set CI SUB 22 Subtract word addressed from accumulator JMP 41 Unconditionally jump to location addressed JE 42 If CI is set to EQUAL, jump to location addressed JH 44 If CI is set to HIGH, jump to location addressed JL 45 If CI is set to LOW, jump to location addressed Program to add list of numbers using a loop. Addressing in loop is done by instruction modification. (NOTE: this is considered a rather poor technique with modern machines.) Object Code Equivalent Assembler Source Code Loc Contents Label Oper Argument Comments 200 11214 LOOP LOAD SUM \ 201 21215 INST ADD LIST > accumulate sum of LIST 202 12214 STORE SUM / elements 203 11213 LOAD COUNT \ 204 22222 SUB ONE > update count 205 12213 STORE COUNT / 206 31221 CMP ZERO \ check to see if done 207 42212 JE DONE / 208 11201 LOAD INST \ 209 21222 ADD ONE > modify ADD LIST 210 12201 STORE INST / instruction 211 41200 JMP LOOP do it again 212 00000 DONE HALT finished -- stop 213 00006 COUNT DW 6 \ 214 00000 SUM DW 0 \ 215 00073 LIST DW 73 \ 216 00024 DW 24 \ 217 99996 DW -4 \ memory initialization 218 00021 DW 21 / with 6 data values 219 99922 DW -78 / and useful constants 220 00101 DW 101 / 221 00000 ZERO DW 0 / 222 00001 ONE DW 1 / END LOOP mark end and specify start