Word Pro – Supplement_MARE_AL
Summary of the MARIE Assembly Language
Terminate the program7HALT
Use the value at X as the address to jump to CJUMPI X
Jump-and-Store: Store the PC at address X and jump to X+10JNS XSubroutine
call and return
Skip the next instruction based on the condition, C:
C = 00016: skip if AC is negative (b11b10 = 002)
C = 40016: skip if the AC = 0 (b11b10 = 012)
C = 80016: skip if the AC is positive (b11b10 = 102)
8SKIPCOND C
Unconditional branch to X by loading the value of X into PC9JUMP XBranch
Output the value in AC to the display6OUTPUT
Input a value from the keyboard into AC5INPUTI/O
Store the contents of AC at address X2STORE X
Load the contents of address X into AC1LOAD XData Transfer
Put all zeros in the ACACLEAR
Add Indirect: Use the value at X as the actual address of the
data operand to add to AC
BADDI X
Subtract the contents of address X from the AC4SUBT X
Add the contents of address X to AC3ADD XArithmetic
DescriptionHex
Opcode
MnemonicType of
Instructions
MARIE
Machine-language
Instruction Format
Opcode Address (or Condition)
15 12 11 10 0
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
0 LOAD X 100616
1 ADD Y 300716
2 SUBT Z 400816
3 STORE RESULT 200916
4 OUTPUT 600016
5 HALT 700016
6 X, DEC 10 000A16
7 Y, DEC 20 001416
8 Z, DEC 5 000516
9 RESULT, DEC 0 000016
The lines at address 6 to 9 are assembler directives (directions to the assembler) to initialize the memory
location associated with X (address 6) to DECimal 10, the memory location associated with Y (address 7) to
20, etc. Lines at address 0 to 5 are the actual machine-language MARIE program. If the PC = 0 (program
counter), the program execution would start at address 0 which contains 100616. This instruction would be
fetched into the CPUs IR (instruction register), bits 15-12 contain the operations code of 116 would be
decoded to determine that it is a LOAD instruction. Execution of the LOAD causes the specified memory
Supplement for Assignment #7 (sections 4.8 – 4.10 of the textbook)
Supplement MARIE AL – page 1
address’s (00616 in bits 11-0) content to be loaded into the accumulator (AC) register (i.e., the value 1010
would be loaded into the AC). 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:
if X < Y then ... else ... end if X < Y? then body else body False True HLL statement Flow chart Assembly Language LOAD X SUBT Y SKIPCOND 000 JUMP ELSE THEN, JUMP END_IF ELSE, END_IF, If X < Y is True, then the value of (X-Y) in the AC is negative. The “SKIPCOND 000” cause the JUMP ELSE instruction to be jumped over if the AC 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 AC will not be negative the SKIPCOND 000 instruction will not jump over the JUMP ELSE instruction. For a loop example, consider the following FOR-loop and corresponding flow-chart: for I = 1 to 10 do I = 1 ... end for I < 10? for body I = I + 1 False True HLL statement Flow chart Assembly Language FOR_INIT, LOAD ONE FOR_COND, LOAD I LOAD I SUBT TEN SKIPCOND 800 JUMP FOR_BODY JUMP FOR_COND FOR_BODY, END_FOR, STORE I STORE I JUMP END_FOR ADD ONE Supplement for Assignment #7 (sections 4.8 - 4.10 of the textbook) Supplement MARIE AL - page 2 If I 10 is False, then (I - 10) is positive, so the SKIPCOND 800 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 4.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 PC b MBR M[MAR] (read from memory into the MBR instead of directly into the IR as descibed on page 199)b IR MBR b However, the authors seem to understand this since their microoperations to execute the Load X (on page 196) use the MBR correctly: MAR X (X is the address part of the IR, so this should technically be MAR IR11 - 0 )b b MBR M[MAR] (read from memory into the MBR instead of directly into the AC)b AC MBR b Revised Figure 4.9 Datapath in MARIE MAR IR PC InREG MBR OutREG AC ALU Memory Address 0 1 2 3 2 - 1 12 16-bits Input Device Output Device16 address data/instr. 1 2 3 4 7 5 6 1 2 3 4 7 5 6 Supplement for Assignment #7 (sections 4.8 - 4.10 of the textbook) Supplement MARIE AL - page 3 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 100 LOAD X 110416 101 ADD Y 310516 102 STORE RESULT 210616 103 HALT 700016 104 X, DEC 35 002316 105 Y, DEC -23 FFE916 106 RESULT, DEC 0 000016 Revised Figure 4.14 (a) LOAD X (110416 in ML) 002300231041104101AC bMBRT6Execute 00231041104101MBR bM[MAR]T5Get operand 11041041104101MAR b IR[11-0]T4Decode IR[15-12] 11041001104101PC b PC + 1T3 11041001104100IR bMBRT2 1104100100MBR bM[MAR]T1 100100MAR b PCT0Fetch 100 (initial values) ACMBRMARIRPCRTNStep #Step Revised Figure 4.14 (b) ADD Y (310516 in ML) 000CFFE91053105102AC b AC + MBRT6Execute 0023FFE91053105102MBR bM[MAR]T5Get operand 002331051053105102MAR b IR[11-0]T4Decode IR[15-12] 002331051013105102PC b PC + 1T3 002331051013105101IR bMBRT2 002331051011104101MBR bM[MAR]T1 002300231011104101MAR b PCT0Fetch 002300231041104101 (initial values AFTER LOAD X) ACMBRMARIRPCRTNStep #Step Revised Figure 4.14 (c) STORE RESULT (210616 in ML) (YOU COMPLETE THIS AS PART OF LECTURE) T5Execute* T4Decode IR[15-12] T3 T2 T1 T0Fetch 000CFFE91053105102 (initial values AFTER ADD Y) ACMBRMARIRPCRTNStep #Step * “Get Operand” step is not necessary for STORE instructions Supplement for Assignment #7 (sections 4.8 - 4.10 of the textbook) Supplement MARIE AL - page 4 Advanced MARIE Assembly Language Example: Print null terminated string to output HLL: index = 0 while str[index] != 0 do output str[index] index = index + 1 end while 000016DEC 0 / NULL CHARNULL, 1F 004416DEC 68 / D1 004C16DEC 76 / L1D 005216DEC 82 / R1C 004F16DEC 79 / O1B 005716DEC 87 / W1A 000D16DEC 13 /carriage return19 004F16DEC 79 / O18 004C16DEC 76 / L17 004C16DEC 76 / L16 004516DEC 69 / E15 004816DEC 72 / HSTR,14 001416HEX 14STR_BASE,13 000016HEX 0ADDR,12 000016DEC 0INDEX,11 000116DEC 1ONE,10 700016HALTEND_WHILE,F 900216JUMP WHILEE 201116STORE INDEXD 300B16ADD ONEC 100D16LOAD INDEXB 600016OUTPUTDO,A 900A16JUMP END_WHILE9 900A16JUMP DO8 840016SKIPCOND 4007 B01216ADDI ADDR6 A00016CLEAR5 201216STORE ADDR4 301116ADD INDEX3 101316LOAD STR_BASEWHILE,2 201116STORE INDEX1 A00016CLEAR 0 Machine LanguageAssembly LanguageLabelAddress Supplement for Assignment #7 (sections 4.8 - 4.10 of the textbook) Supplement MARIE AL - page 5