Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/raffitz/AAC
Browse files Browse the repository at this point in the history
  • Loading branch information
raffitz committed Apr 27, 2015
2 parents 52c7ce1 + a2bed3d commit eb4de09
Show file tree
Hide file tree
Showing 4 changed files with 213 additions and 10 deletions.
23 changes: 13 additions & 10 deletions asm/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@

\*.asm | description
-------------|------------
teste1 | Given by the professor. Tests some jumps
teste3 | Generates the first 20 Fibonnaci numbers
teste4 |
testej | Tests jumps
testef | Tests flags
testesh | Tests shifts
testev | Tests overflows

\*.asm | description
-------------|------------
demo_lab1_1 | Given by the professor. Tests flags
demo_lab1_2 | Given by the professor. Generates primes
demo_lab1_3 | Given by the professor. Selection sort
teste1 | Given by the professor. Tests some jumps
teste3 | Generates the first 20 Fibonnaci numbers
teste4 |
testef | Tests flags
testej | Tests jumps
testesh | Tests shifts
testev | Tests overflows
80 changes: 80 additions & 0 deletions asm/demo_lab1_1.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
.module flags
.pseg
; Testa flags
;
; r0 points to ARR1
lcl r0, LOWBYTE ARR1
lch r0, HIGHBYTE ARR1
zeros r1
inca r2,r1
store r0,r2
inca r0,r0
store r0,r2
inca r0,r0
store r0,r2
inca r0,r0
store r0,r2
inca r0,r0
store r0,r2
inca r0,r0
store r0,r2
inca r0,r0
store r0,r2
inca r0,r0
store r0,r2
inca r0,r0
store r0,r2
deca r0,r0
deca r0,r0
deca r0,r0
deca r0,r0
deca r0,r0
deca r0,r0
deca r0,r0
deca r0,r0
passa r3,r1
jf.zero L1
nop
store r0,r1
L1: inca r0,r0
passb r3,r1
jt.zero L2
nop
store r0,r1
L2: inca r0,r0
zeros r3
deca r3,r3
inca r3,r3
jf.carry L31
nop
store r0,r1
L31: jt.overflow L3
nop
inca r0,r0
store r0,r1
L3: inca r0,r0
lcl r3,255
lch r3,127
inca r3,r3
jf.overflow L4
nop
store r0,r1
L4: inca r0,r0
asr r2,r2
jf.zero L5
nop
inca r2,r2
store r0,r1
L5: inca r0,r0
HLT: j HLT
nop
;;
.dseg
ARR1:
.word 0 ; zero -> errou Z passa (1)
.word 0 ; zero -> errou Z passb (1)
.word 0 ; zero -> errou C inca (1)
.word 0 ; zero -> errou overflow inca (1)
.word 0 ; zero -> errou O deca (1)
.word 0 ; zero -> errou Z asr (1)
.end
61 changes: 61 additions & 0 deletions asm/demo_lab1_2.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
.module teste7
.pseg
main:
; r0 points to the stack
lcl r0, LOWBYTE STACK
lch r0, HIGHBYTE STACK
lcl r6, LOWBYTE DIV
lch r6, HIGHBYTE DIV
loadlit r5,30
; Generate primes until 30. R5 is the limit
loadlit r4,2
; Start at 2
L1: loadlit r2,2
L2: passa r1,r4
jal r6
and r1,r1,r1
jt.zero SKIP
nop
inca r2,r2
sub r1,r4,r2
jf.zero L2
nop
;; Doesn't divide any number
store r0,r4
inca r0,r0
SKIP:
inca r4,r4
sub r3,r4,r5
jf.zero L1
nop
passa r5,r0
lcl r3, LOWBYTE STACK
lch r3, HIGHBYTE STACK
L3: load r1,r3
passb r2,r1
jal r6
nop
store r0,r1
inca r0,r0
inca r3,r3
sub r7,r3,r5
jf.zero L3


HLT: j HLT
nop
; Computes the remainder of R1 divided by R2, both positive
; by doing successive subtractions.
DIV: sub r1,r1,r2
jt.neg ADD
nop
jt.zero RET
nop
j DIV
nop
ADD: add r1,r1,r2
RET: jr r7
nop
.dseg
STACK:
.end
59 changes: 59 additions & 0 deletions asm/demo_lab1_3.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
.module test

;escreve o tamanho do array na posicao 27 (decimal) da memoria, e a partir dai o array inicial
;escrevendo o array ordenado por ordem inversa por cima do mesmo


.pseg

main: ;Implementacao do algoritmo selection sort aplicado a um array
;r2 elemento a ordenar ficando na sua posicao final
;r3 para varrer todos os elementos do array

lcl r0,LOWBYTE ARR1
lch r0,HIGHBYTE ARR1
load r4,r0 ;r4 tem o numero de elementos que constituem o array
add r4,r0,r4 ;r4 tem o endereco final,aponta para a ultima posicao do array a ordenar
inca r0,r0 ;r0 aponta para o primeiro elemento do array a ordenar
passa r1,r0 ;r1 " " " " " "
load r2,r0 ;r2 contem primeiro elemento do array

LOOP: inca r1,r1 ;
load r3,r1 ;
sub r6,r2,r3 ;r6 nao e utilizado apenas interessa o resultado presente à saida da ALU para as flags
jt.negzero TROCA ;r2<=r3 faz troca de posicao no array

CONT:
sub r6,r4,r1 ;r6 nao e utilizado ...
jf.zero LOOP ;r4>r1 o array ainda nao foi todo percorrido continua o loop
sub r6,r4,r0 ;
deca r6,r6 ;necessario para detectar se ja esta na penultima posicao do array na posicao final,nao sendo necessario prosseguir o teste
jt.zero FIM ;r4=r0 array ja esta todo ordenado pode terminar
inca r0,r0 ;actualiza ponteiro para o elemento a ser testado
load r2,r0 ;le elemento seguinte do array
passa r1,r0 ;r1 passa a apontar para a posicao onde vai ser colocado o elemento ordenado
j LOOP

TROCA:
store r0,r3 ;Troca a posicao dos elementos na memoria
store r1,r2 ;
passa r5,r2 ;r5 serve apenas como registo temporario
passa r2,r3 ;troca o conteudo dos registos, pois r2 tem o elemento a colocar na posicao final
passa r3,r5 ;e r3 tem o elemento que vai ser testado se e menor q o elemento que se encontra na posicao final
j CONT ;conjtinua a ordenacao

FIM: j FIM
.dseg

ARR1:
.word 8
.word -1
.word 6
.word 3
.word 4
.word 0
.word 5
.word 1
.word 2
STACK:
.end

0 comments on commit eb4de09

Please sign in to comment.