+ All Categories
Home > Documents > Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to...

Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to...

Date post: 20-Dec-2015
Category:
View: 223 times
Download: 2 times
Share this document with a friend
Popular Tags:
26
Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward. Learn from your mistakes and move on. Reflect on yourself, rather than judging others. Strive to leave this world a bit better place for your being here.
Transcript
Page 1: Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.

Some thoughts: If it is too good to be true, it isn’t.

Success is temporary.

It is hard work to make it simple.

Knowing you did it right is enough reward. Learn from your mistakes and move on.

Reflect on yourself, rather than judging others.

Strive to leave this world a bit better place for your being here.

Page 2: Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.

Chap 5

LC-3 Instructions

Chap 5 Homework – due Wednesday October 29 (today)

Project 2 Designs (Working Schematics) – due Wednesday October 29 (today)

Project 2 Reports – due Wednesday November 5

Names on Breadboards – Please place names on sticky or initials outside and names inside

Page 3: Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.

LC-3 Memory Map

(64K of 16 bit words)

256 words

256 words

23.5 K words

39.5 K words

512 words

Page 4: Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.

The LC-3 Computera von Neumann machine

Memory

PSW (Program Status Word): Bits: 15 10 9 8 2 1 0 | S| |Priority| | N| Z| P|

PSW

The Instruction CycleFetch: Next Instruction from Memory (PC) (points to) next instruction PC (PC) + 1 Decode: Fetched InstructionEvaluate: Instr & Address (es) (find where the data is)Fetch: Operand (s) (get data as specified)Execute: OperationStore: Result (if specified)

Page 5: Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.

Computer Machine Instruction Formats

What is IN an instruction?• Operation code – what to do

• Input Operand(s) – 2 ? where to get input operands (memory, registers)

• Output Operand(s) – 1 ?Where to put results (memory, registers)

What are the major instruction types?• Data Movement (load, store, etc.)

• Operate/Calculate (add, sub, mult, OR, AND, etc.)

• Control (branch, jump to subroutine, etc.)

Page 6: Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.

LC-3 Instructions (Fig 5.3 – Appendix a)

Addressing Modes

•Register (Operand is in one of the 8 registers)

• PC-relative (Operand is “offset” from where the PC points)

• Base + Offset (Base relative) (Operand is “offset” from the contents of a register)

• Immediate (Operand is in the instruction)

• Indirect (The “Operand” points to the real address of Operand

– rather than being the operand)

Page 7: Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.

Example LC-3 Program

• Write a program to add 12 integers and store the result in a Register.

Page 8: Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.

Compute the Sum of 12 Integers Program

• Program begins at location x3000.• Integers begin at location x3100.

R1 x3100R3 0 (Sum)R2 12(count)

R2=0?

R4 M[R1] R3 R3+R4R1 R1+1R2 R2-1

NO

YES

R1: “Array” index pointer (Begin with location 3100)

R3: Accumulator for the sum of integers

R2: Loop counter (Count down from 12)

R4: Temporary register to store next integer

Page 9: Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.

Sum integers from x3100 – x310B

Address Instruction Comments

x3000 1 1 1 0 0 0 1 0 1 1 1 1 1 1 1 1 R1 x3100

x3001 0 1 0 1 0 1 1 0 1 1 1 0 0 0 0 0 R3 0

x3002 0 1 0 1 0 1 0 0 1 0 1 0 0 0 0 0 R2 0

x3003 0 0 0 1 0 1 0 0 1 0 1 0 1 1 0 0 R2 12

x3004 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 1 If Z, goto x300A

x3005 0 1 1 0 1 0 0 0 0 1 0 0 0 0 0 0 Load next value to R4

x3006 0 0 0 1 0 1 1 0 1 1 0 0 0 1 0 0 Add to R3

x3007 0 0 0 1 0 0 1 0 0 1 1 0 0 0 0 1 Increment R1 (pointer)

X3008 0 0 0 1 0 1 0 0 1 0 1 1 1 1 1 1Decrement R2

(counter)

x3009 0 0 0 0 1 1 1 1 1 1 1 1 1 0 1 0 Goto x3004

R1: “Array” index pointer (Begin with location 3100) R3: Accumulator for the sum of integers

R2: Loop counter (Count down from 12) R4: Temporary register to store next integer

Page 10: Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.

The Sum program in “binary”

0011000000000000 ;start x3000x3000 1110001011111111 ;R1=x3100x3001 0101011011100000 ;R3=0x3002 0101010010100000 ;R2=0x3003 0001010010101100 ;R2=R2+12x3004 0000010000000101 ;If z goto x300Ax3005 0110100001000000 ;Load next value into R4x3006 0001011011000100 ;R3=R3+R4x3007 0001001001100001 ;R1=R1+1x3008 0001010010111111 ;R2=R2-1x3009 0000111111111010 ;goto x3004x300A 1111000000100101 ;halt

Page 11: Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.

The Sum program in “hex”

3000 ;start x3000x3000 E2FF ;R1=x3100x3001 56E0 ;R3=0x3002 54A0 ;R2=0x3003 14AC ;R2=R2+12x3004 0405 ;If z goto x300Ax3005 6840 ;Load next value into R4x3006 16C4 ;R3=R3+R4x3007 1261 ;R1=R1+1x3008 14BF ;R2=R2-1x3009 0FFA ;goto x3004x300A F025 ;halt

Page 12: Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.

The Sum program Data in “hex”

3100 ; Begin data at x3100x3100 0001 ; Loc x3100x3101 0002x3102 0004x3103 0008x3104 FFFFx3105 1C10x3106 11B1x3107 0019x3108 0F07x3109 0004x310A 0A00x310B 400F ; Loc x310B

Page 13: Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.

LC3 Edit

• Enter (or Load) the program into LC3 Edit - Store it as prog.bin for a binary file, or

Store it as prog.hex for a hex file - Create a prog.obj file with the Editor

• Enter (or Load) the data into LC3 Edit - Store it as data.bin for a binary file, or Store it as data.hex for a hex file - Create a data.obj file with the Editor

Page 14: Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.

LC3 Edit

Page 15: Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.

LC-3 Simulator

• Open LC-3 Simulator

- Load prog.obj

- Load data.obj

- Initialize values (PC, memory, registers) - Set breakpoint(s) - Step through program checking registers and “memory map” - Debug program

Page 16: Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.

Simulator Screen

Page 17: Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.

Assemble and Test Add program on the Editor and Simulator

• Run program with HALT statement and without breakpoint(s).

• Observe what happens.• Explain.

Page 18: Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.

Write a program to place the absolute value of the [R2] in

R2

How do we compute

A = - A

if we don’t have a subtract instruction?

Code your result and test it.

Page 19: Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.

Example : Multiply

Write program to Multiply two unsigned integers in R4 and R5

How do you begin?

Page 20: Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.

Example : Multiply

• This multiplies two unsigned integers in R4 and R5 and puts the result in R2.

clear R2

add R4 to R2

decrement R5

R5 = 0?

HALT

No

Yes

• Now write the program

Page 21: Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.

x3200 Clear Accumulator (R2) R2 <- 0

x3201 Add [R4] to Accumulator R2 <- R2 + R4

x3202 Dec R5 R5 <- R5 – 1

x3203 Do again if [R5] > 0 BR p x3201

x3204 Stop HALT

• Program to multiply [R4] x [R5] and place the result in

R2

• Now write the machine code

Page 22: Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.

x3200 Clear Accumulator (R2) R2 <- 0 0101 010 010 1 00000 54A0

x3201 Add [R4] to Accumulator R2 <- R2 + R4 0001 010 010 0 00 100 1484

x3202 Dec R5 R5 <- R5 – 1 0001 101 101 1 11111 1B7F

x3203 Do again if [R5] > 0 BR p x3201 0000 001 111111101 03FD

x3204 Stop HALT 1111 0000 00100101 F025

• Program to multiply [R4] x [R5] and place

the result in R2

• Enter the Machine Code in the editor &

• Test it on the Simulator

Page 23: Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.

Example : Multiply

• This program multiplies two unsigned integers in R4 and R5 and accumulates the result in R2.

x3200 0101010010100000x3201 0001010010000100x3202 0001101101111111x3203 0000011111111101x3204 1111000000100101

clear R2

add R4 to R2

decrement R5

R5 = 0?

HALT

No

Yes

R2 <- 0R2 <- R2 + R4 R5 <- R5 – 1BRzp x3201HALT

Page 24: Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.

Occurrences of Inputted Char Program

Count = 0(R2 = 0)

Ptr = 1st file character(R3 = M[x3012])

Input charfrom keybd

(TRAP x23)

Done?(R1 ?= EOT)

Load char from file(R1 = M[R3])

Match?(R1 ?= R0)

Incr Count(R2 = R2 + 1)

Load next char from file(R3 = R3 + 1, R1 = M[R3])

Convert count toASCII character

(R0 = x30, R0 = R2 + R0)

Print count(TRAP x21)

HALT(TRAP x25)

NO

NO

YES

YES

Page 25: Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.

Occurrences of Inputted Char Program (1 of 2)

Address Instruction Comments

x3000 0 1 0 1 0 1 0 0 1 0 1 0 0 0 0 0 R2 0 (counter)

x3001 0 0 1 0 0 1 1 0 0 0 0 1 0 0 1 0 R3 M[x3102] (ptr)

x3002 1 1 1 1 0 0 0 0 0 0 1 0 0 0 1 1 Input to R0 (TRAP x23)

x3003 0 1 1 0 0 0 1 0 1 1 0 0 0 0 0 0 R1 M[R3]

x3004 0 0 0 1 1 0 0 0 0 1 1 1 1 1 0 0 R4 R1 – 4 (EOT)

x3005 0 0 0 0 0 1 0 0 0 0 0 0 1 1 1 0 If Z, goto x300E

x3006 1 0 0 1 0 0 1 0 0 1 1 1 1 1 1 1 R1 NOT R1

x3007 0 0 0 1 0 0 1 0 0 1 1 0 0 0 0 1 R1 R1 + 1

X3008 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 R1 R1 + R0

x3009 0 0 0 0 1 0 1 0 0 0 0 0 1 0 1 1 If N or P, goto x300B

Page 26: Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.

Occurrences of Inputted Char Program (2 of 2)

Address Instruction Comments

x300A 0 0 0 1 0 1 0 0 1 0 1 0 0 0 0 1 R2 R2 + 1

x300B 0 0 0 1 0 1 1 0 1 1 1 0 0 0 0 1 R3 R3 + 1

x300C 0 1 1 0 0 0 1 0 1 1 0 0 0 0 0 0 R1 M[R3]

x300D 0 0 0 0 1 1 1 0 0 0 0 0 0 1 0 0 Goto x3004

x300E 0 0 1 0 0 0 0 0 0 0 0 1 0 0 1 1 R0 M[x3013]

x300F 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 R0 R0 + R2

x3010 1 1 1 1 0 0 0 0 0 0 1 0 0 0 0 1 Print R0 (TRAP x21)

x3011 1 1 1 1 0 0 0 0 0 0 1 0 0 1 0 1 HALT (TRAP x25)

X3012 Starting Address of File

x3013 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 ASCII x30 (‘0’)


Recommended