1 / 9

Introduction to LC-3 Assembly Language

Introduction to LC-3 Assembly Language. LC-3 Assembly Language Syntax. Each line of a program is one of the following: an instruction an assember directive (or pseudo-op) a comment Whitespace (between symbols) and case are ignored. Comments (beginning with “;”) are also ignored.

dory
Télécharger la présentation

Introduction to LC-3 Assembly Language

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to LC-3Assembly Language

  2. LC-3 Assembly Language Syntax • Each line of a program is one of the following: • an instruction • an assember directive (or pseudo-op) • a comment • Whitespace (between symbols) and case are ignored. • Comments (beginning with “;”) are also ignored. • An instruction has the following format: LABEL OPCODE OPERANDS ;COMMENTS optional mandatory

  3. Assembler Directives • Pseudo-operations • do not refer to operations executed by program • used by assembler • look like instruction, but “opcode” starts with dot

  4. An Assembly Language Program ; ; Program to multiply a number by the constant 6 ; .ORIG x3050 LD R1, SIX LD R2, NUMBER AND R3, R3, #0 ; Clear R3. It will ; contain the product. ; The inner loop ; AGAIN ADD R3, R3, R2 ADD R1, R1, #-1 ; R1 keeps track of BRp AGAIN ; the iteration. ; HALT ; NUMBER .BLKW 2 SIX .FILL x0006 ; .END Symbol Table: Symbol Address AGAIN x3053 NUMBER x3057 SIX x3059

  5. One Pass vs Two Pass Assemblers • Two Pass – Checks for syntax errors and builds the Symbol Table during first pass, resolves operand addresses during second pass. • One Pass – Checks for syntax errors, builds the Symbol Table, and resolves operand addresses during the first pass. So why have a two pass?

  6. More than One Object (Load) File • Symbol Table Symbols Externals Exports Addresses Start x3000 Number x300A Data ? Value ? • The “Linker/Loader” would generate another “global table to resolve • Externals & Exports at Load time

  7. Trap Codes • LC-3 assembler provides “pseudo-instructions” foreach trap code, so you don’t have to remember them.

  8. An Assembly Language Program ; ; Program to multiply a number by the constant 3 ; .ORIG x3050 LD R1, SIX LD R2, NUMBER AND R3, R3, #0 ; Clear R3. It will ; contain the product ; ; Multiply by adding ; AGAIN ADD R3, R3, R2 ADD R1, R1, #-1 ; R1 keeps track of BRp AGAIN ; the iteration ; HALT ; ; Data ; NUMBER .BLKW 1 SIX .FILL x0003 ; .END

  9. Program to add two integers .ORIG x3000 ; begin at x3000 ; input two numbers TRAP x23 ;input an integer character LD R3, HEXN30 ;subtract x30 to get integer ADD R0, R0, R3 ADD R1, R0, x0 ;move the first integer to register 1 TRAP x23 ;input another integer ADD R0, R0, R3 ;subtract x30 to get integer ; add the numbers ADD R2, R0, R1 ;add the two integers ; print the results LEA R0, MESG ;load the address of the message string TRAP x22 ;"PUTS" outputs a string ADD R0, R2, x0 ;move the sum to R0, to be output LD R3, HEX30 ;add 30 to integer to get integer character ADD R0, R0, R3 TRAP x21 ;display the sum ; stop HALT ; data MESG .STRINGZ "The sum of those two numbers is: “ HEXN30 .FILL xFFD0 HEX30 .FILL x0030 .END

More Related