Phần cứng - Chapter 7: LC - 2 assembly language

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.

ppt11 trang | Chia sẻ: huyhoang44 | Lượt xem: 977 | Lượt tải: 0download
Bạn đang xem nội dung tài liệu Phần cứng - Chapter 7: LC - 2 assembly language, để tải tài liệu về máy bạn click vào nút DOWNLOAD ở trên
Chapter 7LC-2 Assembly LanguageExample01 ;02 ; Program to multiply a number by six03 ;04 .ORIG x305005 LD R1, SIX06 LD R2, NUMBER07 AND R3, R3, #0 ; clear R308 ;09 ; The inner loop0A ;0B AGAIN ADD R3, R3, R20C ADD R1, R1, #-1 ; keep track of iterations0D BRp AGAIN0E ;0F HALT10 ;11 NUMBER .BLKW 112 SIX .FILL x000613 ;14 .END2Assembly Language InstructionsFormatsLABEL OPCODE OPERANDS ; COMMENTSLABEL PSEUDO-OPS ; COMMENTSLabelLabel is a symbolic name that refers to a memory location.It is used to:indicate the target of a branch instruction, e.g. AGAIN in location 0Bstore a value in a memory location, e.g. NUMBER and SIXCommentsintended for humans only: explanation of code, visual display3Pseudo-OpsAre directives to the assemblerAssembler: 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.4Examples .ORIG x3000 AND R1, R1, #0 ADD R1, R1, #10 LD R2, Twenty LD R3, EssTwenty FILL x0014Ess .FILL “S” .BLKW 2 .STRINGZ “Hi” .BLKW 3 .ENDx3000: AND R1, R1, #0x3001: ADD R1, R1, #10x3002: LD R2, #4x3003: LD R3, #5x3004: x0014 ; 0000 0000 0001 0100x3005: x0053 ; 0000 0000 0101 0011x3006:x3007:x3008: x0048 ; Hx3009: x0069 ; ix300A: x0000 ; null terminated stringx300B:x300C:x300D:5The Assembly ProcessObjectiveTranslate the AL (Assembly Language) program into ML (Machine Language).Each AL instruction yields one ML instruction word.Interpret pseudo-ops correctly.ProblemAn instruction may reference a label.If the label hasn’t been encountered yet, the assembler can't form the instruction wordSolutionTwo-pass assembly6Two-Pass Assembly - 1First PassScan each lineKeep track of current addressIncrement by 1 for each instructionAdjust as required for any pseudo-ops (e.g. .FILL or .STRINGZ, etc.)For each labelEnter it into the symbol tableAllocate to it the current addressStop when find .END7Two-Pass Assembly - 2Second PassScan each line againTranslate each AL instruction into MLLook up any symbols in the symbol tableDetermine operand field for the instructionCheck for errors if reference crosses page boundariesA reference to an undefined symbol is an errorFill memory locations as directed by pseudo-opsStop when find .END8Symbol Table From the previous example: ; ; Program to multiply a number by six ; .ORIG x3050x3050 LD R1, SIXx3051 LD R2, NUMBERx3052 AND R3, R3, #0 ; ; The inner loop ;x3053 AGAIN ADD R3, R3, R2x3054 ADD R1, R1, #-1 x3055 BRp AGAIN ;x3056 HALT ;x3057 NUMBER .BLKW 1x3058 SIX .FILL x0006 ; .END9Object File Each source file is translated into an object file: the executable image. A complete program may include several source and/or object files:Source files written by the programmerLibrary files provided by the system (OS or other) The object files must be linkedNeed to provide a copy of the symbol tableInclude it in the header of the object file10Example - ParityParity is a function that returns a 1 when the number of 1s in a word is odd and 0 when it is even. .ORIG x30003000 AND R2, R2, x0 ; clear R23001 LDI R1, Input ; load word into R13002 Count BRz Report ; if 0, done counting3003 BRp Shift ; if >0, skip ADD3004 ADD R2, R2, x1 ; increment count3005 Shift ADD R1, R1, R1 ; shift left 1 bit 3006 BRnzp Count ; go back up3007 Report AND R3, R2, x1 ; LSB 1 or 0?3008 STI R3, Output ; store results3009 TRAP x25 ; halt program300A Input .FILL x3200 ; address of input300B Output .FILL x3201 ; address of output11

Các file đính kèm theo tài liệu này:

  • pptnajjar_chap7_9262.ppt