Docsity

17 LC-3 Assembly Cheat Sheet, Schemes and Mind Maps of Assembly Language Programming

Toggle sidebar
bg1
Instruction
Action
Addressing Mode
ADD R2, R2, R3
R2 = R2 + R3
Register
ADD R2, R2, #1
R2 = R2 + 1
Immediate
AND R2, R2, R3
Register
AND R2, R2, #0
R2 = R2 AND 0
Immediate
BR[n][z][p] LABEL
If [n][z][p] Go to LABEL
CC, PC-relative
JMP R1
PC = R1
Register
JSR
JSRR
LD R2, LABEL
R2 = m[LABEL]
Register, PC-relative
LDI R2, LABEL
R2 = m[m[LABEL]]
Register, Indirect
LDR R2, R0, #n6
R2 = m[R0+n]
Base Register
LEA R2, LABEL
R2 = LABEL
Register, PC-relative
NOT R2, R1
R2 = NOT(R1)
Register
RET
RTI
ST R2, LABEL
m[LABEL] = R2
Register, PC-relative
STI R2, LABEL
m[m[LABEL] = R2
Register, Indirect
STR R2, R0, #n6
m[R0 + n] = R2
Register, Base Register
TRAP (HALT)
Today:
CS Information Session at 4:00p
ALL majors/minors should attend.
(Check your e-mail for sign up)
Talk: What is Data Science?
At 6:00p (check your email for sign up)
17 LC-3 Assembly Cheat Sheet
Tuesday, April 20, 2021
9:30 AM
240 Lectures Page 1
pf3
pf4
pf5

Partial preview of the text

Download 17 LC-3 Assembly Cheat Sheet and more Schemes and Mind Maps Assembly Language Programming in PDF only on Docsity!

Instruction Action Addressing Mode ADD R2, R2, R3 R2 = R2 + R3 Register ADD R2, R2, #1 R2 = R2 + 1 Immediate AND R2, R2, R3 (^) R2 = R2 AND R3 Register AND R2, R2, #0 (^) R2 = R2 AND 0 Immediate BR[n][z][p] LABEL (^) If [n][z][p] Go to LABEL CC, PC-relative JMP R1 (^) PC = R1 Register JSR JSRR LD R2, LABEL (^) R2 = m[LABEL] Register, PC-relative LDI R2, LABEL (^) R2 = m[m[LABEL]] Register, Indirect LDR R2, R0, #n 6 R2 = m[R0+n] Base Register LEA R2, LABEL (^) R2 = LABEL Register, PC-relative NOT R2, R1 (^) R2 = NOT(R1) Register RET RTI ST R2, LABEL m[LABEL] = R2 Register, PC-relative STI R2, LABEL m[m[LABEL] = R2 Register, Indirect STR R2, R0, #n 6 m[R0 + n] = R2 Register, Base Register TRAP (HALT) Today: CS Information Session at 4:00p ALL majors/minors should attend. (Check your e-mail for sign up) Talk: What is Data Science? At 6:00p (check your email for sign up)

17 LC-3 Assembly Cheat Sheet

Tuesday, April 20, 2021 9:30 AM

Problem: Write a complete LC-3 program to perform integer division on two numbers, A and B. Assume that A is stored in location x6000 and B is in x6001. The integer division should produce two results: a quotient (stored in R0 ) and a remainder (stored in R1 ). For example, Suppose A = 22 and B = 7. Then, after division R0 will contain 3 and R1 will contain 1.

17 PLC-3 Assembly

Tuesday, April 20, 2021 9:30 AM

count = 0 c = input character nextCH = next character in string while nextCH != NULL do if nextCH = c then count = count + 1 nextCH = next character in string output count

17 Counting Characters

Tuesday, April 20, 2021 9:30 AM

; Program to count the occurrences of a character in a string. ; Program inputs the character to count from keyboard. ; The string is provided starting from memory location x4000 (NULL terminated). ; e.g. if the string is "BRYN MAWR" ; and the input char is 'R' ; the output displayed will be 2 ; ; Assume the count will always be less than 10 (why??) .ORIG x START AND R2, R2, #0 ; R2 = 0 (count) LD R3, PTR ; Address of string TRAP x23 ; R0 = input char LDR R1, R3, #0 ; R1 = next char ; ; WHILE R1 is not NULL DO LOOP BRz OUTPUT ; next char is null ; ; IF char in R1 = R NOT R1, R ADD R1, R1, #1 ; R1 = - R ADD R1, R1, R0 ; R1 = R0 - R BRnp NEXTCH ; THEN ADD R2, R2, #1 ; R2 = R2 + 1 (incr count) ; NEXTCH ADD R3, R3, #1 ; incr char pointer LDR R1, R3, #0 ; R1 = next char BR LOOP ; ; Output count OUTPUT LD R0, ASCII ; Load ASCII template in R ADD R0, R0, R2 ; Add count to R0 (ASCII count) TRAP x21 ; Output count in ASCII HALT ; ; STORAGE ASCII .FILL x PTR .FILL x .END .ORIG x MESG .STRINGZ "BRYN MAWR" .END

17 The LC-3 Program

Tuesday, April 20, 2021 9:30 AM