Supplement for Assignment # (sections.8 -. of the textbook) Summary of the MARIE Assembly Language Type of Instructions Arithmetic Data Transfer I/O Branch Subroutine call and return Mnemonic ADD X SUBT X ADDI X LOAD X STORE X INPUT OUTPUT JUMP X SKIPCOND C JNS X JUMPI X HALT Hex Opcode B A 9 8 C Description Add the contents of address X to Subtract the contents of address X from the Add Indirect: Use the value at X as the actual address of the data operand to add to Put all zeros in the Load the contents of address X into Store the contents of at address X Input a value from the keyboard into Output the value in to the display Unconditional branch to X by loading the value of X into PC Skip the next instruction based on the condition, C: C = : skip if is negative (b b = ) C = : skip if the = (b b = ) C = 8 : skip if the is positive (b b = ) Jump-and-Store: Store the PC at address X and jump to X+ Use the value at X as the address to jump to Terminate the program MARIE Machine-language Instruction Format Opcode Address (or Condition) A simple MARIE program can be written to perform the high-level language statements: RESULT = X + Y - Z print RESULT Address Label Assembly Language Machine Language LOAD X ADD Y SUBT Z 8 STORE RESULT 9 OUTPUT HALT X, DEC A Y, DEC 8 Z, DEC 9 RESULT, DEC The lines at address to 9 are assembler directives (directions to the assembler) to initialize the memory location associated with X (address ) to DECimal, the memory location associated with Y (address ) to, etc. Lines at address to are the actual machine-language MARIE program. If the PC = (program counter), the program execution would start at address which contains. This instruction would be fetched into the CPUs IR (instruction register), bits - contain the operations code of would be decoded to determine that it is a LOAD instruction. Execution of the LOAD causes the specified memory Supplement MARIE AL - page
Supplement for Assignment # (sections.8 -. of the textbook) address s ( in bits -) content to be loaded into the accumulator () register (i.e., the value would be loaded into the ). During the fetch-decode-execute cycle, the PC would get incremented to the next instruction. The program instructions are executed sequentially until the HALT instruction which stops the program. The branch instructions, JUMP and SKIPCOND, potentially cause the PC to jump (i.e., alter the flow of control in the program). These instructions are useful for implementing high-level language selection (IF, IF-THEN-ELSE, SWITCH, etc.) and looping statements (FOR, WHILE, REPEAT, etc.). For example, consider the following IF-THEN-ELSE statement and corresponding flow-chart: HLL statement Flow chart Assembly Language LOAD X if X < Y then X < Y? False SUBT Y SKIPCOND JUMP ELSE True THEN, then body else JUMP END_IF ELSE, else body end if END_IF, If X < Y is True, then the value of (X-Y) in the is negative. The SKIPCOND cause the JUMP ELSE instruction to be jumped over if the is negative. Since the then-part code follows the JUMP ELSE instruction, it is only executed if X < Y. After the then-part code is executed, the JUMP END_IF causes the else-body to be skipped. If X < Y is False, then the value of (X - Y) in the will not be negative the SKIPCOND instruction will not jump over the JUMP ELSE instruction. For a loop example, consider the following FOR-loop and corresponding flow-chart: HLL statement Flow chart Assembly Language for I = to do I = I <? True for body False FOR_INIT, LOAD ONE STORE I FOR_COND, LOAD I SUBT TEN SKIPCOND 8 JUMP FOR_BODY JUMP END_FOR FOR_BODY, end for I = I + LOAD I ADD ONE STORE I JUMP FOR_COND END_FOR, Supplement MARIE AL - page
Supplement for Assignment # (sections.8 -. of the textbook) If I [ is False, then (I - ) is positive, so the SKIPCOND 8 skips to JUMP END_FOR. Thus, dropping out of the FOR loop. Otherwise, the JUMP FOR_BODY is not skipped. After the for-body executes and the loop-control variable I is incremented, the JUMP FOR_COND loops back to recheck the loop control variable. The simplicity of the MARIE instruction set make writing assembly-language programs difficult. So, we ll only write small toy programs in MARIE, and later learn to write realistic assembly-language programs in the slightly more complex MIPS instruction set. However, the simplicity of the MARIE architecture is a huge benefit as we turn our attention to the hardware of implementing the CPU datapath and control unit. MARIE Registers and Buses: The revised Figure.9 (below) has moved the Memory from the CPU chip and hence the internal CPU Datapath. Thus, memory can only be accessed via the MAR (Memory-Address Register) and the MBR (Memory-Buffer Register) which is much more realistic. This has some impact on the microoperations that access memory. For example, fetching the instruction pointed at by the PC into the IR would require the following microoperations: MAR b PC MBR b M[MAR] (read from memory into the MBR instead of directly into the IR as descibed on page 99) IR b MBR However, the authors seem to understand this since their microoperations to execute the Load X (on page 9) use the MBR correctly: MAR b X (X is the address part of the IR, so this should technically be MAR b IR - ) MBR b M[MAR] (read from memory into the MBR instead of directly into the ) b MBR Revised Figure.9 Datapath in MARIE MAR PC MBR IR InREG ALU address data/instr. Memory -bits Input Device Address - OutREG Output Device Supplement MARIE AL - page
The text discusses the microoperations of the fetch-decode-execute machine cycle in the execution of the Simple Program below that calculates RESULT = X + Y. Address Label Assembly Language Machine Language LOAD X ADD Y STORE RESULT HALT X, DEC Y, DEC - FFE9 RESULT, DEC Step Decode IR[-] Get operand Execute Supplement for Assignment # (sections.8 -. of the textbook) Revised Figure. (a) LOAD X ( in ML) Step # PC IR MAR MBR (initial values) T MARbPC T MBRbM[MAR] T IRbMBR T PCbPC + T MARbIR[-] T MBRbM[MAR] bmbr T Revised Figure. (b) ADD Y ( in ML) Step Step # PC IR MAR MBR (initial values AFTER LOAD X) T MARbPC T MBRbM[MAR] T IRbMBR T PCbPC + Decode IR[-] T MARbIR[-] Get operand T MBRbM[MAR] FFE9 Execute b + MBR FFE9 C T Revised Figure. (c) STORE RESULT ( in ML) (YOU COMPLETE THIS AS PART OF LECTURE) Step Step # PC IR MAR (initial values AFTER ADD Y) T T T T Decode IR[-] T Execute* T * Get Operand step is not necessary for STORE instructions MBR FFE9 C Supplement MARIE AL - page
Advanced MARIE Assembly Language Example: Print null terminated string to output HLL: index = while str[index]!= do output str[index] index = index + end while Address 8 9 A B C D E F 8 9 A B C D F Supplement for Assignment # (sections.8 -. of the textbook) Label WHILE, DO, END_WHILE, ONE, INDEX, ADDR, STR_BASE, STR, NULL, Assembly Language STORE INDEX LOAD STR_BASE ADD INDEX STORE ADDR ADDI ADDR SKIPCOND JUMP DO JUMP END_WHILE OUTPUT LOAD INDEX ADD ONE STORE INDEX JUMP WHILE HALT DEC DEC HEX HEX DEC / H DEC 9 / E DEC / L DEC / L DEC 9 / O DEC /carriage return DEC 8 / W DEC 9 / O DEC 8 / R DEC / L DEC 8 / D DEC / NULL CHAR Machine Language A A B 8 9A 9A D B 9 8 C C F D F C Supplement MARIE AL - page