+ All Categories
Home > Documents > LC-3 and Assembly code (2) - cs.auckland.ac.nz · `Input and output:Input and output: Get...

LC-3 and Assembly code (2) - cs.auckland.ac.nz · `Input and output:Input and output: Get...

Date post: 24-Mar-2019
Category:
Upload: dodiep
View: 224 times
Download: 0 times
Share this document with a friend
10
LC-3 and Assembly code (2)
Transcript

LC-3 and Assembly code (2)

Minh Nguyen, email: mngu012@aucklanduni ac [email protected]:

Office hours:

After tutorial 4 you have learntAfter tutorial 4, you have learnt ◦ how to install LC-3 simulator◦ Edit LC-3 assembly codes in editorEdit LC 3 assembly codes in editor◦ Run simple programs◦ Debug LC-3 by using Step over buttong y g pRun over tutorial 4 quickly once more time if needed.

chapter7 code: 7 1 asmchapter7_code: 7.1.asmWhat s the program doing?◦ Program multiplies an integer by the constant 6Program multiplies an integer by the constant 6.◦ Before execution, an integer must be stored in NUMBER.◦ Result stored in R3Operations used: ◦ Ld $(register), VariableName ;load value to register from

memory◦ And $(register), $(register), #(decimalNumber) ;bitwise

operationp◦ BRp Label ;branch (goto) to a Label in memory if register

is positive

Input and output:Input and output: ◦ Get characters from keyboard to memory/register◦ Print characters from memory/register to screenPrint characters from memory/register to screenTry running GetC.asm◦ Program does: get 1 input from keyboard and printProgram does: get 1 input from keyboard and print

that out to screen.Operations for input/output can be used:p p / p◦ Getc◦ Out◦ In◦ Puts

GetCGetC◦ It takes a character from keyboard◦ Store it in Register R0 (ascii value)OutOut◦ It takes ascii value stored in R0◦ Print the correspondent character out to screenIIn◦ It prints out a line ask user to input◦ It takes a character from keyboard◦ Store it in Register R0 (ascii value)Puts◦ It prints out a StringIt prints out a String◦ Look at printString.asm

By getC and Out, you can input 1 character andBy getC and Out, you can input 1 character and output 1 character at a time. In order to input and output more, you need loops.Loops can be created by using Br (branch operation)Loops can be created by using Br (branch operation)BR {n|z|p} LabelBRn branch to Label if register is negativeBR b h t L b l if i t iBRz branch to Label if register is zeroBRp branch to Label if register is positive

BRzp, BRzn, BRpn…p, , pBRnzp branch without any conditionClearer explanation: http://www lc3help com/tutorials/Basic LC-http://www.lc3help.com/tutorials/Basic_LC3_Instructions

BR asmBR.asmExample1.asmExample2 asmExample2.asmOthers

Exercise asmExercise.asmInput a number from 0 to 9Print out all the number from 0 to thatPrint out all the number from 0 to that numberSk l t d i iSkeleton code in exercise.asmExample:

I 4◦ Input: 4◦ Output: 0 1 2 3 4


Recommended