Download The LC-2 Instruction Set Architecture - Pages

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Introduction to Computer
Engineering
CS/ECE 252, Spring 2017
Rahul Nayar
Computer Sciences Department
University of Wisconsin – Madison
Demo : PenSim
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Note for all
•
•
•
•
•
HW 5 is due today
Remember to staple your HWs
• you will loose 2 points if not stapled
HW 6 will be released at 11 am today
HW 6 involves programing and you are
required to submit your part of the HW solutions
in “learn@UW”
For those of you already here, please take out
your laptops and write algorithm and LC-3
instructions to solve the question on the left
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Download Pensim
PennSim:
The PennSim LC-3 Simulator can be run on any computer with Java
1.5 installed. Please see the PennSim Guide below for more
information.
•
•
•
•
PennSim Guide
PennSim Software
PennSim Manual
PennSim's lc3 OS
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
File Types
• You will encounter at least two filetypes when using PennSim:
• .OBJ
These files are the "machine" code that can be loaded and executed by
PennSim. It contains sequences of 16-bit binary values that correspond
to LC-3 instructions. These files are unreadable in a text editor and will
be created for you by PennSim's assembler function.
• .ASM
These files contain LC-3 assembly code. Each line contains a single
assembly instruction. For example, ADD R0, R0, #1 is a single assembly
instruction. In order to convert a .asm file into a .obj file, it must be run
through an assembler. This should be done through PennSim and is
discussed in the PennSim Guide.
6-5
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Editors
• Creating .ASM Files
• You may use any basic file editor that you would like to
create .asm files. Be sure to save the file with a .asm file
extension. Many text editors default to .txt, which will not
work with PennSim. Here are some text editors that may
work well:
• Windows: Notepad, Notepad++, LC-3 Edit (see below)
• Mac: TextEdit, TextWrangler
• Linux: gedit
• Any: vi, emacs
6-6
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
In-Class Exercise
Come up with an algorithm that searches for the minimum
integer in 100 memory locations starting from 0x5a00, and
sets R7 to the minimum integer. Your solution should use a
looping construct. Note: Both positive and negative integers
are allowed.
a) Show the algorithm as a flowchart by decomposing it into
its basic constructs.
b) Convert the above algorithm to an LC-3 program. Write the
program in LC-3 binary code. Comment each line of code ​.
The program should start at memory address x4000.
6-7
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
In-Class Exercise: Decision Points
• Registers to use:
• R0 as counter register
• R6 as address register
• R7 will have the minimum value
• Idea
•
•
•
•
set R7 to a (positive) large value say #10000
In this case we set it to the first value
iterate over each memory locations and compare its value with R7
if R7 > d[memAddr]
➢update R7 = d[memAddr]
6-8
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
In-Class Exercise: Algorithm
6-9
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
In-class Exercise:Instructions
.orig x4000
loop_start:
count_inc:
LD R0, #100 ;loop counter
LD R6, x5a00 ;R6 <- x5a00
LDR R7, R6, 0 ;R7 initialized to M[x5a00]
LDR R1, R6, 0 ;R1 <- M[x5a00]
NOT R2, R1
ADD R2, R2, #1 ;R2 = -R1
ADD R3, R2, R7 ;R3 = R7-R1, if positive, update min
BRnz count_inc
ADD R7, R1, #0 ;R7 = R1 , updated min
ADD R6, R6, #1
ADD R0, R0, #-1
BRp loop_start
HALT
6-10
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
In-class Exercise:Instructions
0100 0000 0000 0000 ;.orig x4000
0010 0000 0000 1101 ; LD R0, val ;loop counter
0010 1100 0000 1011 ; LD R6, addr1 ;R6 <- x5a00
0110 1111 1000 0000 ; LDR R7, R6, 0 ;R7 initialized to M[x5a00]
0110 0011 1000 0000 ; loop_start: LDR R1, R6, 0 ;R1 <- M[x5a00]
1001 0100 0111 1111 ; NOT R2, R1
0001 0100 1010 0001 ; ADD R2, R2, #1 ;R2 = -R1
0001 0110 1000 0111 ; ADD R3, R2, R7 ;R3 = R7-R1, if positive, updatemin
0000 1100 0000 0001 ; BRnz count_inc
0001 1110 0110 0000 ; ADD R7, R1, #0 ;R7 = R1 , updated min
0001 1101 1010 0001 ; count_inc: ADD R6, R6, #1
0001 0000 0011 1111 ; ADD R0, R0, #-1
0000 0011 1111 0111 ; BRp loop_start
1111 0000 0010 0101 ; HALT 0101 1010 0000 0000 ; addr1 .FILL x5a00
0000 0000 0110 0100 ; val .FILL x0064
6-11
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
In-class Exercise:script
reset
load lc3os.obj
load example.obj
load test.obj
set PC x4000
break set x400c
continue
check r7 x8000
6-12