Top Banner
Assembly and LC-3 Simulator (2) Assembly and LC 3 Simulator (2)
13

Assembly and LCand LC-3 Simulator (2)Simulator (2) · `Include 2 frames: console (likes computer screen) `Registers and values stored in register computer screen) and simulator (computer)

Mar 24, 2019

Download

Documents

vanhuong
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Assembly and LCand LC-3 Simulator (2)Simulator (2) · `Include 2 frames: console (likes computer screen) `Registers and values stored in register computer screen) and simulator (computer)

Assembly and LC-3 Simulator (2)Assembly and LC 3 Simulator (2)

Page 2: Assembly and LCand LC-3 Simulator (2)Simulator (2) · `Include 2 frames: console (likes computer screen) `Registers and values stored in register computer screen) and simulator (computer)

Download links are provided in tutorial pageAfter installation, you will see 2 exe programs (windows): LC3Edit.exe and Simulate.exe.

LC3Edit is editor program (IDE).Simulate is LC3 simulator program (virtualSimulate is LC3 simulator program (virtual computer which execute assembly code).

Page 3: Assembly and LCand LC-3 Simulator (2)Simulator (2) · `Include 2 frames: console (likes computer screen) `Registers and values stored in register computer screen) and simulator (computer)

You can edit your program here using binary code, hexadecimal code and assembly code.After finish editing, you can export to .obj file which can be run by LC3 simulator.

Page 4: Assembly and LCand LC-3 Simulator (2)Simulator (2) · `Include 2 frames: console (likes computer screen) `Registers and values stored in register computer screen) and simulator (computer)

Include 2 frames: console (likes computer screen)

Registers and values stored in register computer screen)

and simulator (computer)

registerMemory and values stored in memory

Page 5: Assembly and LCand LC-3 Simulator (2)Simulator (2) · `Include 2 frames: console (likes computer screen) `Registers and values stored in register computer screen) and simulator (computer)

Each program should be placed in it's own .asm file. The files should be entitled *.asm like example.asm...The files should be entitled .asm like example.asm... Each program should begin in memory at address x3000. This is accomplished via the .ORIG directive, which should be the first line in each file. The end of the program should consist of two lines: theThe end of the program should consist of two lines: the penultimate line should contain the HALT instruction, and the last line in the file should contain the .END directive to inform the assembler that this is the end of the program. So all of assembly files should be of the following form:So… all of assembly files should be of the following form:◦ .ORIG x3000 ◦ ... ◦ your code goes here◦ ... ◦ HALT ◦ .END See example programs.

Page 6: Assembly and LCand LC-3 Simulator (2)Simulator (2) · `Include 2 frames: console (likes computer screen) `Registers and values stored in register computer screen) and simulator (computer)
Page 7: Assembly and LCand LC-3 Simulator (2)Simulator (2) · `Include 2 frames: console (likes computer screen) `Registers and values stored in register computer screen) and simulator (computer)

To subtract A with B we:◦ Turn B to be –B ◦ Invert all bits of B◦ Add 1 to that so we have 2’s complement of –B◦ Add 1 to that so we have 2 s complement of B

ld r1 xld r2 y

t 2 2not r2, r2add r2, r2, #1;now just add normally r4 = r1 + r2 add r4, r1, r2, ,;declare some number say x = 10 y = 20x .fill #10y .fill #20

Page 8: Assembly and LCand LC-3 Simulator (2)Simulator (2) · `Include 2 frames: console (likes computer screen) `Registers and values stored in register computer screen) and simulator (computer)

To copy registers:◦ Just need to use ADD

ld r1 xld r2 y

k 1 2;make r1 = r2add r1,r2,#0x .fill #10y .fill #20

To initialise a register to 0:◦ Use AND with 0

y .fill #20

◦ Use AND with 0

and r1, r1, #0

Page 9: Assembly and LCand LC-3 Simulator (2)Simulator (2) · `Include 2 frames: console (likes computer screen) `Registers and values stored in register computer screen) and simulator (computer)

To left shift:◦ Left shift is the same as multiply by 2◦ Multiply by 2 is the same as addition with itself◦ So just need to add itself◦ So just need to add itself

ld r1 x;to left shift use addddadd r1, r1, r1

;to left shift use addadd r1, r1, r1;to left shift use add;to left shift use addadd r1, r1, r1halt ; this means program end;declare some number say x = 10 y = 20

fill #10x .fill #10

Page 10: Assembly and LCand LC-3 Simulator (2)Simulator (2) · `Include 2 frames: console (likes computer screen) `Registers and values stored in register computer screen) and simulator (computer)

Input/output here are all via ASCII table◦ Get characters from keyboard to memory/register◦ Print characters from memory/register to screenOperations for input/output can be used:Operations for input/output can be used:◦ Getc◦ Out◦ In◦ PutsT G CTry GetC.asm

Page 11: Assembly and LCand LC-3 Simulator (2)Simulator (2) · `Include 2 frames: console (likes computer screen) `Registers and values stored in register computer screen) and simulator (computer)

GetC◦ It takes a character from keyboard◦ It takes a character from keyboard◦ Store it in Register R0 (ascii value)Out◦ It takes ascii value stored in R0◦ It takes ascii value stored in R0◦ Print the correspondent character out to screenIn◦ It prints out a line ask user to inputIt prints out a line ask user to input◦ It takes a character from keyboardStore it in Register R0 (ascii value)PutsPuts◦ It prints out a String◦ Look at printString.asm

Page 12: Assembly and LCand LC-3 Simulator (2)Simulator (2) · `Include 2 frames: console (likes computer screen) `Registers and values stored in register computer screen) and simulator (computer)

By getC and Out, you can input 1 character and output 1 character at a time In order to inputoutput 1 character at a time. In order to input and output more, you need loops.Loops can be created by using BR (branch operation)operation)◦ BR {n|z|p} Label◦ BRn branch to Label if register is negative◦ BRz branch to Label if register is zerog◦ BRp branch to Label if register is positive

BRzp, BRzn, BRpn…◦ BRnzp branch without any conditionM l iMore explanation:◦ http://www.lc3help.com/tutorials/Basic_LC-

3_Instructions

Page 13: Assembly and LCand LC-3 Simulator (2)Simulator (2) · `Include 2 frames: console (likes computer screen) `Registers and values stored in register computer screen) and simulator (computer)

Create a program to print all alphabets:◦ From A to ZStart the first question of your assignment