diff --git a/ass1/arith.asm b/ass1/arith.asm new file mode 100644 index 0000000..24354b0 --- /dev/null +++ b/ass1/arith.asm @@ -0,0 +1,49 @@ +arith START 0 + + . seštevek: sum = x + y + LDA x + ADD y + STA sum + + . razlika: diff = x - y + LDA x + SUB y + STA diff + + . produkt: prod = x * y + LDA x + MUL y + STA prod + + . količnik: quot = x / y + LDA x + DIV y . + STA quot + + . ostanek: mod = x - y * (x / y) + STA qtemp + + LDA y + MUL qtemp + STA prodtmp + + LDA x + SUB prodtmp + STA mod + +HALT J HALT + +.data +x WORD 5 +y WORD 2 + +sum RESW 1 +diff RESW 1 +prod RESW 1 +quot RESW 1 +mod RESW 1 + +qtemp RESW 1 +prodtmp RESW 1 + + END arith diff --git a/ass1/arithr.asm b/ass1/arithr.asm new file mode 100644 index 0000000..69453f4 --- /dev/null +++ b/ass1/arithr.asm @@ -0,0 +1,59 @@ +.code +arithr START 0 + + LDA x ; A = x + LDB y ; B = y + + RMO A,S ; S = x + RMO B,T ; T = y + +. sum = x + y + RMO S,A ; A = x + ADDR T,A ; A = x + y + STA sum + +. diff = x - y + RMO S,A ; A = x + SUBR T,A ; A = x - y + STA diff + +. prod = x * y + RMO S,A ; A = x + RMO T,B ; B = y + MULR B,A ; A = x * y + STA prod + +. quot = x / y + RMO S,A ; A = x + RMO T,B ; B = y + DIVR B,A ; A = x / y + STA quot + + +. mod = x % y = x - (x / y)*y + RMO S,A + RMO T,B + DIVR B,A ; A = q = x/y + RMO A,L ; L = q (shrani) + + RMO T,A ; A = y + RMO L,B ; B = q + MULR B,A ; A = y*q = produkt + + RMO S,B ; B = x + SUBR A,B ; B = x - (y*q) + STB mod + +HALT J HALT + +.data +x WORD 5 +y WORD 2 + +sum RESW 1 +diff RESW 1 +prod RESW 1 +quot RESW 1 +mod RESW 1 + + END arithr diff --git a/vhod_izhod/cat.asm b/ass1/cat.asm similarity index 99% rename from vhod_izhod/cat.asm rename to ass1/cat.asm index 32b9908..6bb74d4 100644 --- a/vhod_izhod/cat.asm +++ b/ass1/cat.asm @@ -3,6 +3,7 @@ cat START 0 CLEAR X + read RD #0 STCH BUFF, X diff --git a/ass1/poly.asm b/ass1/poly.asm new file mode 100644 index 0000000..6fcddae --- /dev/null +++ b/ass1/poly.asm @@ -0,0 +1,57 @@ +poly START 0 + + . potence x^1 .. x^4 + LDA x + STA x1 + + MUL x + STA x2 + + MUL x + STA x3 + + MUL x + STA x4 + + + . x3 = 2 * x^3 + LDA x3 + LDB #2 + MULR A,B + STB x3 + + . x2 = 3 * x^2 + LDA x2 + LDB #3 + MULR A,B + STB x2 + + . x1 = 4 * x + LDA x1 + LDB #4 + MULR A,B + STB x1 + + . vsota vseh + LDA x0 + ADD x1 + ADD x2 + ADD x3 + ADD x4 + STA result + + +HALT J HALT + END poly +.data +x WORD 2 ; vrednost x + +x4 RESW 1 +x3 RESW 1 +x2 RESW 1 +x1 RESW 1 +x0 WORD 5 ; konstanta + +result RESW 1 + + END poly diff --git a/ass1/stack.asm b/ass1/stack.asm new file mode 100644 index 0000000..a61cbea --- /dev/null +++ b/ass1/stack.asm @@ -0,0 +1,56 @@ +.code + +stack START 0 + + LDA #9 + STA @stackptr + JSUB stackpush + + JSUB stackpop + LDA @stackptr + +halt J halt + + +stackinit + STA stacktmp + + LDA #STACK + STA stackptr + + LDA stacktmp + RSUB + + +stackpush + STA stacktmp + + LDA stackptr + ADD #3 + STA stackptr + + LDA stacktmp + RSUB + + +stackpop + STA stacktmp + + LDA stackptr + SUB #3 + STA stackptr + + LDA stacktmp + RSUB + + +.data + +stackptr WORD 0 + +stacktmp WORD 0 + +STACKSIZE EQU 50 +STACK RESW STACKSIZE + + END stack