assembly and lcassembly and lc-3 assignment hints ... · convert eachh d lh character to decimal:...

8
Assembly and LC-3 Assignment hints/helps Assembly and LC 3 Assignment hints/helps

Upload: others

Post on 03-Feb-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Assembly and LC-3 Assignment hints/helpsAssembly and LC 3 Assignment hints/helps

;want: input to R0 and create subroutine to convert ascii number to real numberorig x3000.orig x3000

lea r0, stringInput ;input characterputsgetc ;read input;now input is stored in r0 ;copy it to r2;now input is stored in r0 ;copy it to r2add r2, r0, #0;create subroutine to read r2 and store real decimal value in r2jsr charToBinhalthaltcharToBinst r7, savRegld r3, minus0add r2, r2, r3add r2, r2, r3ld r7, savRegretminus0 .fill #-48stringInput .stringz "Please input number: "stringInput .stringz Please input number: savReg .blkw 1.end

’ lIt’s trivialSteps:◦ Create strings:

“Please enter a number: ”“The input is: ”Create a memory to store

using Label BLKW {number} //maybe 5using Label .BLKW {number} //maybe 5◦ Use PUTS to print the strings out◦ Use GETC to get input from keyboard◦ Store input onto memory using STRp y g◦ Use OUT to put character onto Screen◦ Loop using BR… and break whenever Enter (0xA or #10)

is pressed.

Requirement: Finished Part 1Hints:Hints:◦ Read input from memory stored in Part 1, one

character eachh h d l◦ Convert each character to decimal:

If (intput from ‘0’ to ‘9’) ‘0’ = #49 number 0 = ‘0’ – 49 take away 49 for each yinput character to get its decimal value

If (input from ‘A’ to ‘F’)‘A’ = #65 number 10 = ‘A’ – 55 take away 55 forA #65 number 10 A 55 take away 55 for each input character to get its decimal value

◦ Can apply the psudo code on next page

Void printBinary(int x){If(x>=8) {print ‘1’; x-=8;}pelse print ‘0’;If(x>=4) {print ‘1’; x-=4;}else print ‘0’;If(x>=2) {print ‘1’; x =2;}If(x>=2) {print 1 ; x-=2;} else print ‘0’If(x>=1) print ‘1’; else print ‘0’;

}

Input = 3 output = 0011put 3 output 00Input = 13 output = 1101

Requirement: Part 2Hints:◦ After get A, B to binary, store them in memory

location labeled A Blocation labeled A, B◦ Create a subroutine doing addition C = A+B store

result in location labeled CC b i h B B b◦ Create subroutine to change B to –B by

Invert all bits and add 1◦ Then call D = A + (-B) store result in D( )◦ Create subroutine to read binaries in D and print

the corresponding ‘1’ or ‘0’

Requirement: Part 3Hints: ◦ The first 5 bits are always: 01001-xxxxxxxxxxx◦ The last 11 bits are the distance from address of

the instruction to the address of label minus 1◦ Look at example:

300A – 3000 = 10 – 1 = 9 = 000000010013009 – 300A = -1 – 1 = -2 = 111111111103012 – 3000 = 18 -1 = 17 = 00000010001

◦ Ranges: only 11 bits available to store signed binaryWhen is it too far?When is it too far?