Little Computer 3 (LC3) A Simple Architecture

2y ago
261 Views
11 Downloads
1.27 MB
28 Pages
Last View : Today
Last Download : 3m ago
Upload by : Joao Adcock
Transcription

BinghamtonUniversityCS-120Summer 2015Little Computer 3 (LC3)A Simple ArchitectureText: Introduction to Computer Systems : Sections 4.1, 4.3, 5.1.2,5.1.3, 5.1.4, 5.1.5, 5.2

BinghamtonUniversityCS-120Summer 2015Computer vs. Adding MachineWhat is the difference?

BinghamtonUniversityCS-120Summer 2015Computers are ProgrammableWhat is a computer program?

BinghamtonUniversityCS-120Summer 2015Computer Program Definition (Wikipedia) A computer program, or just a program, is a sequenceof instructions, written to perform a specified task on a computer. A computer requires programs to function, typically executing theprogram's instructions in a central processor. The program has an executable form that the computer can usedirectly to execute the instructions. The same program in its human-readable source code form, fromwhich executable programs are derived (e.g., compiled)

BinghamtonUniversityCS-120Summer 2015Executable Instructions Like a sentence with a verb and a noun and an object What to do add, subtract, move, What to do it on Data in the instruction? Data in memory? Data from a file? Where to put the resultwhile (a getc()) {a a 1;sum sum a;}

BinghamtonUniversityCS-120Summer 2015“Instruction Set Architecture” (ISA)ISA

BinghamtonUniversityISA Contents The instructions the hardware recognizes add, move, get, The data types the instructions can work on two’s complement binary, ascii character, unsigned binary, etc. The data the instructions can work on Registers Memory The external interfaces supported by the instructions File I/O Exception Handling and InterruptsCS-120Summer 2015

BinghamtonUniversityCS-120Summer 2015Little Computer 3 (LC3).orig x3000ADD R1,R1,9ADD R2,R2,10ADD R3,R3,11ADD R1,R2,R3ADD R3,R1,R3HALT.end; R1 - R1 9; R2 - R2 10; R3 - R3 11; R1 - R3 R3 10 11 21; R3 - R1 R3 21 11 32LC3 ISA (Text, Appendix A)LC3 - X86 Translator

BinghamtonUniversityCS-120Summer 2015LC3 Data Types All data is represented as a 16 bit word:15141312111098765432100010100000011100Also represented with 4 hex digits, e.g. 0x281C A word can be interpreted as: a 16 bit unsigned binary number: 0 (216-1) 65,535a 16 bit two’s complement binary number: -32,768 32,767Two ASCII charactersAbsolute Address in Memory: 0x0000 0xFFFFLC3 Instruction

BinghamtonUniversityCS-120Summer 2015LC3 General Purpose Registers 8 Registers labeled R0, R1, R7 Each register16 bits (1 word, four hex chars) wide Fast Read/Write All computation from/to registers No explicit data type! Value undefined (X) until xXXXX0xXXXX0xXXXX

BinghamtonUniversityCS-120Summer 2015LC3 Instructions Smallest (Atomic) directive to LC3 “hardware” Two Flavors Man-readable “Assembly” Machine Readable “Object Code” or “Machine Code” or “Binary” Translation ASSEMBLYADD R1,R1,9ADD R2,R2,10ADD R3,R3,11ADD R1,R2,R3ADD 30x16430xF025DISASSEMBLYASSEMBLYADD R1 R1 #9ADD R2 R2 #10ADD R3 R3 #11ADD R1 R2 R3ADD R3 R1 R3TRAP x25

BinghamtonUniversityCS-120Summer 2015LC3 InstructionAssemblyObject Single Line of Text Label – optional, Col. 1 text Operation Code (OPCODE) 1 word (16 bytes) No labels Operation Code (OPCODE) Type of instruction 2/3 letter mnemonic Operands depend on opcode Comment – optional follows “;” Type of instruction 4 bit binary number (0-F) Operands depend on opcode No comments

BinghamtonUniversityCS-120Summer 2015LC3 Assembly Operands Operands separated by commas “,” Registers: R0, R1, , R7 (or r0, r1, , r7) Literal: Decimal number: decimal digits e.g. 10, 321, -7, . Optional “#” prefix, #10, #321, #-7 Hexadecimal number: x hex digits e.g. x10, xFFFF String: “ characters ” e.g. “Enter a number” Label Reference: Any string not a register, literal, or “reserved” word (opcode mnemonic) Must appear as a label in some other instruction

BinghamtonUniversityCS-120Summer 2015LC3 Operand Conventions Destination – where to put the result of this instruction Always (almost) First Operand Source(s) – Where to get the data for this instruction Always (almost) Second (& Third Operands) e.g.ADD R1,R2,R3 ; R1 R2 R3 Source can match destination e.g.ADD R1,R1,R3 ; Increment R1 by R3 Both sources may be the same e.g.ADD R2,R1,R1 ; R2 2 x R1

BinghamtonUniversityCS-120Summer 2015ADD Instruction (Register Operands)AssemblyObject Mnemonic: ADD Destination Register (Rz) Source Register 1 (Ra) Opcode: 0001 (0x1) DR (3 bit subfield) SR1 (3 bit subfield) Pad 0b000 SR2 (3 bit subfield)e.g. 0b0001 001 010 000 011 0x1283 Source Register 2 (Rb)e.g. add R1,r2,r3Adds value in SR1(Ra) to value in SR2(Rb), stores result in DR (Rz)

BinghamtonUniversityHardware for ADD: add r1,r2,r3CS-120Summer 2015

BinghamtonUniversityCS-120Summer 2015ADD (Reg/Immediate Operands)AssemblyObject Mnemonic: ADD Destination Register (Rz) Source Register 1 (Ra) Opcode: 0001 (0x1) DR (3 bit subfield) SR1 (3 bit subfield) Literal Flag: 0b1 IMM5: 5 bit 2’s comp binarye.g. 0b0001 001 010 1 01010 0x12AA -16 Literal value 15e.g. add R1,r2,#10Adds value in SR1(Ra) to literal value, stores result in DR (Rz)

BinghamtonUniversityCS-120Summer 2015LC3 AND Instruction (Register Operands)AssemblyObject Mnemonic: AND Destination Register (Rz) Source Register 1 (Ra) Opcode: 0101 (0x5) DR (3 bit subfield) SR1 (3 bit subfield) Pad 0b000 SR2 (3 bit subfield)e.g. 0b0101 001 010 000 011 0x5283 Source Register 2 (Rb)e.g. and R1,r2,r3bitwise ands value in SR1(Ra) with value in SR2(Rb), stores result in DR (Rz)

BinghamtonUniversityCS-120Summer 2015AND (Reg/Immediate Operands)AssemblyObject Mnemonic: AND Destination Register (Rz) Source Register 1 (Ra) Opcode: 0101 (0x5) DR (3 bit subfield) SR1 (3 bit subfield) Literal Flag: 0b1 IMM5: 5 bit 2’s comp binarye.g. 0b0101 001 010 1 01010 0x52AA -16 Literal value 15e.g. add R1,r2,#10Bitwise ands value in SR1(Ra) with literal value, stores result in DR (Rz)

BinghamtonUniversityCS-120Summer 2015NOT InstructionAssemblyObject Mnemonic: NOT Destination Register (Rz) Source Register 1 (Ra) Opcode: 1001 (0x9) DR (3 bit subfield) SR1 (3 bit subfield) Pad 0b111111e.g. 0b1001 001 010 111111 0x92BFe.g. not R1,r2Inverts value in SR1(Ra), stores result in DR (Rz)

BinghamtonUniversityCS-120Summer 2015LC3 Boilerplate Start a program with: .orig x3000 Defines where to put the program in memory more to come End a program with: HALT.end HALT is an instruction which tells OS not to look for more instructions .end tells assembler not to look for more instructions

BinghamtonUniversityCS-120Summer 2015LC3 Instruction Cycle (1st Draft)Start at x3000Move HALT

BinghamtonUniversityCS-120Summer 2015LC3 IdiomsANDR3,R4,#0; Zero register 3ADDR4,R3,#0; Copy R3 to R4ADDR3,R3,#1; Increment Register 3NOTADDR4,R3R4,R4,#1; R4 -R3ADDR4,R3,R3; R4 R3 x 2

BinghamtonUniversityCS-120Summer 2015Example L3 Program: SpecificationWrite an LC3 program using AND, ADD, and NOT to put the value“100” into register 2. Use as few instructions as possible.

BinghamtonUniversityCS-120Summer 2015Example LC3 Program (6 instructions).orig x3000AND R1,R1,#0ADD R1,R1,#15ADD R1,R1,R1ADD R2,R1,R1ADD R2,R2,R1ADD R2,R2,#10HALT.end;;;;;;R1 0R1 0 15R1 15 15 30R2 30 30 60R2 60 30 90R2 90 10 100

BinghamtonUniversityCS-120Summer 2015Example LC3 Program.orig x3000AND R1,R1,#0ADD R1,R1,#10ADD R1,R1,R1ADD R2,R1,R1ADD R2,R2,R2ADD R2,R2,R1HALT.end;;;;;;R1 0R1 0 10 10R1 10 10 20R2 20 20 40R2 40 40 80R2 80 20 100

BinghamtonUniversityCS-120Summer 2015Example LC3 Program.orig x3000AND R2,R2,#0ADD R2,R2,#15ADD R2,R2,R2ADD R2,R2,R2ADD R2,R2,#-10ADD R2,R2,R2HALT.end;;;;;;R2 0R2 15R2 30R2 30 30 60R2 60 -10 50R2 50 50 100

BinghamtonUniversityCS-120Summer 2015Example LC3 Program – 5 instructions!.orig x3000AND R2,R2,#0ADD R2,R2,#15ADD R2,R2,#10ADD R2,R2,R2ADD R2,R2,R2HALT.end;;;;;R2 0R2 15R2 25R2 50R2 100

Computer Program Definition (Wikipedia) A computer program, or just a program, is a sequence of instructions, written to perform a specified task on a computer. A computer requires programs to function, typically executing the program's instructions in a central processor. The program has an e

Related Documents:

The LC3 represents a standard, basic CPU. Compiling C code for the LC3 produces simple assembly language code, which is translated to LC3 machine code.

Subroutines and TRAP Routines in LC3 1 SubroutinesinLC3 we covered TRAP routines System calls to process I/O (or other system tasks) Written by system, called by user ØResides aspart of system code Steps: Call, Process, Return Subroutines –i.e., functions Written by user Called by user program Steps: Call, Process .

TRAP instruction. used by program to transfer control to operating system 8-bit trap vector names one of the 256 service routines §4. A linkage back to the user program. want execution to resume immediately after the TRAP instruction 27 28 LC3 TRAP Routines and their Assembler Names vector symbol routine x20GETCread a single character .

Tutorial Week 6 –LC3 and Assembly 1 . Something worth doing: review the TRAP service routines for LC-3. Title: Slide 1 Author: A W Created Date: 4/21/2010 4:00:38 PM .

TRAP x22 PUTS écrit à l'écran la chaîne de caractères pointée par R0 TRAP x23 IN lit au clavier un caractère ASCII, l'écrit à l'écran, et le place dans l'octet de poids faible de R0 Nicolas Louvet Programmation en assembleur du LC3. 21 mars 2016 9 / 35

TRAP x22 PUTS écrit à l'écran la chaîne de caractères pointée par R0 TRAP x23 IN lit au clavier un caractère ASCII, l'écrit à l'écran, et le place dans l'octet de poids faible de R0 (Université Claude Bernard Lyon 1) Programmation en assembleur du LC3. 18 octobre 20189/21 Plan 1 Programmation en assembleur du LC-3

4 7 LC-3 Overview: Memory and Registers Memory o address space: 216locations (16-bit addresses) o addressability: 16 bits Registers o temporary storage, accessed in a single machine cycle § accessing memory generally takes longer than a single cycle o eight general-purpose registers: R0 -R7 § each 16 bits wide § how many bits to uniquely identify a register?

Annual Thanksgiving Service at St Mark’s Church St Mark’s Rise, Dalston E8 on Sunday 19 September 2004 at 4 pm . 2 . Order of Service Processional hymn — all stand All things bright and beautiful, All creatures great and small, All things wise and wonderful: The Lord God made them all. Each little flower that opens, Each little bird that sings, He made their glowing colors, He made their .