Download presentation
Presentation is loading. Please wait.
1
Introduction to LC-3 Assembly 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 optionalmandatory
3
Assembler Directives Pseudo-operations –do not refer to operations executed by program –used by assembler –look like instruction, but “opcode” starts with dot OpcodeOperand Meaning.ORIG addressstarting address of program.END end of program.BLKW nallocate n words of storage.FILL nallocate one word, initialize with value n.STRINGZ n-character string allocate n+1 locations, initialize w/characters and null terminator
4
An Assembly Language Program ; ; Program to multiply a number by the constant 6 ;.ORIGx3050 LDR1, SIX LDR2, NUMBER ANDR3, R3, #0; Clear R3. It will ; contain the product. ; The inner loop ; AGAINADDR3, R3, R2 ADDR1, R1, #-1; R1 keeps track of BRpAGAIN; the iteration. ; HALT ; NUMBER.BLKW2 SIX.FILLx0006 ;.END Symbol Table: Symbol Address AGAINx3053 NUMBERx3057 SIXx3059
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” for each trap code, so you don’t have to remember them. CodeEquivalentDescription HALTTRAP x25 Halt execution and print message to console. INTRAP x23 Print prompt on console, read (and echo) one character from keybd. Character stored in R0[7:0]. OUTTRAP x21 Write one character (in R0[7:0]) to console. GETCTRAP x20 Read one character from keyboard. Character stored in R0[7:0]. PUTSTRAP x22 Write null-terminated string to console. Address of string is in R0.
8
An Assembly Language Program ; ; Program to multiply a number by the constant 3 ;.ORIGx3050 LDR1, SIX LDR2, NUMBER ANDR3, R3, #0; Clear R3. It will ; contain the product ; ; Multiply by adding ; AGAINADDR3, R3, R2 ADDR1, R1, #-1; R1 keeps track of BRpAGAIN; the iteration ; HALT ; ; Data ; NUMBER.BLKW1 SIX.FILLx0003 ;.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.FILLxFFD0 HEX30.FILLx0030.END
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.