Chapter 7 - LC-2 assembly language. The main contents of this chapter include all of the following: Assembly language programming - Moving up a level, an assembly language program, the assembly process, beyond the assembly of a single assembly language program. | Chapter 7 LC-2 Assembly Language Example 01 ; 02 ; Program to multiply a number by six 03 ; 04 .ORIG x3050 05 LD R1, SIX 06 LD R2, NUMBER 07 AND R3, R3, #0 ; clear R3 08 ; 09 ; The inner loop 0A ; 0B AGAIN ADD R3, R3, R2 0C ADD R1, R1, #-1 ; keep track of iterations 0D BRp AGAIN 0E ; 0F HALT 10 ; 11 NUMBER .BLKW 1 12 SIX .FILL x0006 13 ; 14 .END 7 - Assembly Language Instructions Formats LABEL OPCODE OPERANDS ; COMMENTS LABEL PSEUDO-OPS ; COMMENTS Label Label is a symbolic name that refers to a memory location. It is used to: indicate the target of a branch instruction, . AGAIN in location 0B store a value in a memory location, . NUMBER and SIX Comments intended for humans only: explanation of code, visual display 7 - Pseudo-Ops Are directives to the assembler Assembler: the program that will translate human-readable assembly language into machine instructions. LC-2 Pseudo-Ops: .ORIG address Tells assembler where to locate the program in memory (starting address). .END Marks the end of the source program. .BLKW n Set aside a block of n words in memory. .FILL value Store value in the next location in memory .STRINGZ string Store the string, one character per word, in memory. Add a word of x0000 after the string. .EXTERNAL The label so indicated is allocated in another module. 7 - Examples .ORIG x3000 AND R1, R1, #0 ADD R1, R1, #10 LD R2, Twenty LD R3, Ess Twenty FILL x0014 Ess .FILL “S” .BLKW 2 .STRINGZ “Hi” .BLKW 3 .END x3000: AND R1, R1, #0 x3001: ADD R1, R1, #10 x3002: LD R2, #4 x3003: LD R3, #5 x3004: x0014 ; 0000 0000 0001 0100 x3005: x0053 ; 0000 0000 0101 0011 x3006: x3007: x3008: x0048 ; H x3009: x0069 ; i x300A: x0000 ; null terminated string x300B: x300C: x300D: 7 - The Assembly Process Objective Translate the AL (Assembly Language) program into ML (Machine Language). Each AL instruction yields one ML instruction word. Interpret pseudo-ops correctly. Problem An instruction may reference a label. If the label hasn’t been encountered . | Chapter 7 LC-2 Assembly Language Example 01 ; 02 ; Program to multiply a number by six 03 ; 04 .ORIG x3050 05 LD R1, SIX 06 LD R2, NUMBER 07 AND R3, R3, #0 ; clear R3 08 ; 09 ; The inner loop 0A ; 0B AGAIN ADD R3, R3, R2 0C ADD R1, R1, #-1 ; keep track of iterations 0D BRp AGAIN 0E ; 0F HALT 10 ; 11 NUMBER .BLKW 1 12 SIX .FILL x0006 13 ; 14 .END 7 - Assembly Language Instructions Formats LABEL OPCODE OPERANDS ; COMMENTS LABEL PSEUDO-OPS ; COMMENTS Label Label is a symbolic name that refers to a memory location. It is used to: indicate the target of a branch instruction, . AGAIN in location 0B store a value in a memory location, . NUMBER and SIX Comments intended for humans only: explanation of code, visual display 7 - Pseudo-Ops Are directives to the assembler Assembler: the program that will translate human-readable assembly language into machine instructions. LC-2 Pseudo-Ops: .ORIG address Tells assembler where to locate the program in memory (starting address). .END .