Initial commit

This commit is contained in:
Isaac Shoebottom 2023-05-25 18:39:26 -03:00
commit 9804827a09
41 changed files with 278 additions and 0 deletions

BIN
Assigments/1/A1.pdf Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

32
Assigments/2/A2.asm Normal file
View File

@ -0,0 +1,32 @@
.ORIG x3000 ;start point
AND R6, R6, #0 ;clean R6
AND R5, R5, #0 ;clean R5
;load memory addresses into registers
LDI R3, x00D
LDI R4, x00D
;NOT the divident to get negative value and then add one
NOT R5, R4 ; NOT(R4) => R5
ADD R5, R5, #1 ; R5+1 => R5;
BR #1; skip first increment
ADD R6, R6, #1 ;increment divison count
ADD R3, R3, R5 ;subtract
BRz #-3 ;if exact division we can skip final loop
BRp #-4 ;loop back 3 instructions to keep dividing
ADD R3, R3, R4 ; get the remainder of the division
;store values in memory;
STI R6, x005
STI R3, x005
HALT
.fill x0000
.fill x4000
.fill x4001
.fill x5000
.fill x5001
.end

24
Assigments/2/A2.bin Normal file
View File

@ -0,0 +1,24 @@
0011 000 000000000 ;start point x3000
0101 110 110 1 00000 ;clean R6
0101 101 101 1 00000 ;clean R5
;load memory addresses into registers
1010 011 000001101
1010 100 000001101
;NOT the divident to get negative value and then add one
1001 101 100 1 11111 ; NOT(R4) => R5
0001 101 101 1 00001 ; R5+1 => R5;
0000 1 1 1 000000001 ; skip first increment
0001 110 110 1 00001 ;increment divison count
0001 011 011 000 101 ;subtract
0000 0 1 0 111111101 ;if exact division we can skip final loop
0000 0 0 1 111111100 ;loop back 3 instructions to keep dividing
0001 011 011 000 100 ; get the remainder of the division
;store values in memory;
1011 110 000000101
1011 011 000000101
1111 0000 00100101 ;halt

BIN
Assigments/2/A2.obj Normal file

Binary file not shown.

BIN
Assigments/2/A2.pdf Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

24
Assigments/2/divide.bin Normal file
View File

@ -0,0 +1,24 @@
0011 000 000000000 ;start point x3000
0101 110 110 1 00000 ;clean R6
0101 101 101 1 00000 ;clean R5
;load memory addresses into registers
1010 011 000001101
1010 100 000001101
;NOT the divident to get negative value and then add one
1001 101 100 1 11111 ; NOT(R4) => R5
0001 101 101 1 00001 ; R5+1 => R5;
0000 1 1 1 000000001 ; skip first increment
0001 110 110 1 00001 ;increment divison count
0001 011 011 000 101 ;subtract
0000 0 1 0 111111101 ;if exact division we can skip final loop
0000 0 0 1 111111100 ;loop back 3 instructions to keep dividing
0001 011 011 000 100 ; get the remainder of the division
;store values in memory;
1011 110 000000101
1011 011 000000101
1111 0000 00100101 ;halt

View File

@ -0,0 +1,30 @@
0011 000 000000000 ;start point x3000
0101 110 110 1 00000 ;clean R6
0101 101 101 1 00000 ;clean R5
;load memory addresses into registers
1010 011 000001101
1010 100 000001101
;NOT the divident to get negative value and then add one
1001 101 100 1 11111 ; NOT(R4) => R5
0001 101 101 1 00001 ; R5+1 => R5;
0000 1 1 1 000000001 ; skip first increment
0001 110 110 1 00001 ;increment divison count
0001 011 011 000 101 ;subtract
0000 0 1 0 111111101 ;if exact division we can skip final loop
0000 0 0 1 111111100 ;loop back 3 instructions to keep dividing
0001 011 011 000 100 ; get the remainder of the division
;store values in memory;
1011 110 000000101
1011 011 000000101
1111 0000 00100101 ;halt
0000 0000 0000 0000
1100 0000 0000 0000
1011 1111 1111 1111
1011 0000 0000 0000
1010 1111 1111 1111

BIN
Assigments/3/A3.pdf Normal file

Binary file not shown.

38
Assigments/3/A3a.asm Normal file
View File

@ -0,0 +1,38 @@
;first, clean registers
;second, load x4002 into a register
;third, determine if negative or positive
;fourth depending on what it is, add it to memory location
;stop when reaching a memory location of zero
.ORIG x3000 ;start point
AND R6, R6, #0 ;clean R6
AND R5, R5, #0 ;clean R5
AND R4, R4, #0 ;clean R4
AND R3, R3, #0 ;clean R3
STI R3, NEGATIVEPOS ;clean memory at location
STI R3, POSITIVEPOS ;clean memory at location
LOOP LD R6, POSITION ;load position into register
ADD R6, R6, #1 ;Add one to register
ST R6, POSITION ;Store new value in memory
LDI R3, POSITION ;Load from new value
ADD R3, R3, #0 ;test for negative
BRz DONE ;Halt if result is zero
BRn NEGATIVE ;Branch if negative
BRp POSITIVE ;branch if positive
NEGATIVE LDI R4, NEGATIVEPOS ;load negatve total into r4
ADD R4, R4, R3 ;add stored value together with new value
STI R4, NEGATIVEPOS ;store the new total back to negative total
BR LOOP ;loop back
POSITIVE LDI R5, POSITIVEPOS ;load positive total into r5
ADD R5, R5, R3 ;add stored value together with nuew value
STI R5, POSITIVEPOS ;store the new total back into positive total
BR LOOP ;loop back
DONE HALT ;kill program
POSITIVEPOS .fill x4000
NEGATIVEPOS .fill x4001
POSITION .fill x4001
.END

BIN
Assigments/3/A3a.obj Normal file

Binary file not shown.

42
Assigments/3/A3b.asm Normal file
View File

@ -0,0 +1,42 @@
;clean registers
;load starting pos and starting pos +1 into memory
;subtract first value (starting pos) from second value (starting pos +1)
;if result is negative or zero, write 0 to x4000
;if positive, loop back and do the same with the next two memory locations
.ORIG x3000 ;start point
AND R6, R6, #0 ;clean R6
AND R5, R5, #0 ;clean R5
AND R4, R4, #0 ;clean R4
AND R3, R3, #0 ;clean R3
LOOP LD R6, FIRSTPOS ;block loads first pos into register increments memory value by one and store back
ADD R6, R6, #1
ST R6, FIRSTPOS
LD R6, SECONDPOS ;block loads second pos into register increments memory value by one and store back
ADD R6, R6, #1
ST R6, SECONDPOS
LDI R3, FIRSTPOS ;load values into memory and then create negative out of it
LDI R4, SECONDPOS
ADD R4, R4, #0 ;see if the array ends
BRz FINISH
NOT R3, R3
ADD R3, R3, #1
ADD R5, R3, R4 ;add R3 and R4 into R5
BRp LOOP
LD R6, ZERO
STI R6, RESULT
HALT
FINISH LD R6, ONE
STI R6, RESULT
DONE HALT
FIRSTPOS .fill x4000
SECONDPOS .fill x4001
RESULT .fill x4000
ONE .fill x0001
ZERO .fill x0000
.END

BIN
Assigments/3/A3b.obj Normal file

Binary file not shown.

15
Assigments/3/Example.asm Normal file
View File

@ -0,0 +1,15 @@
.ORIG x3000
LD R2, ZERO
LD R0, M0
LD R1, M1
LOOP BRz DONE
ADD R2, R2, R0
ADD R1, R1, #-1
BR LOOP
DONE ST R2, RESULT
HALT
RESULT .FILL x0000
ZERO .FILL x0000
M0 .FILL x0004
M1 .FILL x0803
.END

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
Assigments/4/A4.pdf Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

View File

@ -0,0 +1,23 @@
.ORIG x3000
LD R0, NUM
LD R1, DEN
JSR GCD
ADD R4, R1, #0
ADD R1, R2, #0
JSR DIVIDE
ST R2, NUM
ADD R0, R4, #0
JSR DIVIDE
ST R2, DEN
HALT
; you can try other values for NUM and DEN by replacing these values in the simulator
NUM .FILL #10 ; you can try other values for NUM and DEN by replacing
DEN .FILL #3
; Divide R0 by R1, putting quotient in R2 and remainder in R3
DIVIDE
; Euclid's algorithm for GCD of R0 and R1, result in R2
GCD
.END

46
Assigments/4/fraction.asm Normal file
View File

@ -0,0 +1,46 @@
.ORIG x3000
LD R0, NUM
LD R1, DEN
JSR GCD
ADD R4, R1, #0
ADD R1, R2, #0
JSR DIVIDE
ST R2, NUM
ADD R0, R4, #0
JSR DIVIDE
ST R2, DEN
HALT
; you can try other values for NUM and DEN by replacing these values in the simulator
NUM .FILL #81 ; you can try other values for NUM and DEN by replacing
DEN .FILL #24
; Divide R0 by R1, putting quotient in R2 and remainder in R3
DIVIDE AND R2, R2, #0 ;clean R2
NOT R3, R1 ;store NOT of r1 in R3
ADD R3, R3, #1 ;add one to make R3 the negative of R1
ADD R5, R0, #0 ;store num in working variable
DIVLOOP ADD R2, R2, #1 ;first increment of quotient counter
ADD R5, R5, R3 ;store working number in R4, subtracting the denominator from the numerator
BRz DIVFIN
BRn DIVREM
BRp DIVLOOP
DIVREM ADD R3, R5, R1
ADD R2, R2, #-1
AND R5, R5, #0 ; clean r4
RET
DIVFIN AND R3, R3, #0 ;remainder is zero
AND R5, R5, #0 ; clean r4
RET
; Euclid's algorithm for GCD of R0 and R1, result in R2
GCD ADD R6, R7, #0 ;make call stack work (store the ret value of the original call)
GCDLOOP JSR DIVIDE
ADD R0, R1, #0 ; R0 = R1
ADD R1, R3, #0 ; R1 = R3
BRp GCDLOOP
ADD R2, R0, #0 ;result in R2
ADD R7, R6, #0 ;make call stack work (load the original ret value to return to original call location)
LD R0, NUM ;load values back into r0 (bc im bad at programming)
LD R1, DEN ;load values back into r1 (bc im bad at programming)
RET
.END

BIN
Assigments/4/fraction.obj Normal file

Binary file not shown.

BIN
Assigments/5/A5.pdf Normal file

Binary file not shown.

BIN
Assigments/6/A6.pdf Normal file

Binary file not shown.

BIN
L10-LC3_Intro.pdf Normal file

Binary file not shown.

BIN
LC3 Instruction Set.pdf Normal file

Binary file not shown.

BIN
LC3Tools-Setup-2.0.1.exe Normal file

Binary file not shown.

4
test.asm Normal file
View File

@ -0,0 +1,4 @@
.ORIG x3000
TRAP x25
.end

BIN
test.obj Normal file

Binary file not shown.