That's not how you call a chicken!

This commit is contained in:
2015-06-09 17:35:48 +02:00
parent 3f4c3007c7
commit 29aeccb147

View File

@@ -4,45 +4,45 @@
* Date : 2015-06-09
* Description: RTFT
*-----------------------------------------------------------
ORG $3000
ORG $3000 ; Start at address 3000
* Put program code here
FACTORIZATION:
move.l #2, D2
move.l #2, D2 ; Store the constant 2 into data register D2
FACTORIZATION_LOOP:
move.l D0, D3
divu D2, D0
swap D0
cmp.w #0, D0
beq FACTOR_FOUND
move.l D0, D3 ; Store the value in the register D0 into data register D3
divu D2, D0 ; Divide the value in the register D0 with the value in the register D2 and store the quotient in the right half and the remainder in the left half of data register D0
swap D0 ; Swaps the first two and the last two bytes in data register D0
cmp.w #0, D0 ; Compare the constant 0 and the value in the register D0
beq FACTOR_FOUND ; Jump to label FACTOR_FOUND if the value in the register D0 == the constant 0
add.w #1, D2
move.l D3, D0
bra FACTORIZATION_LOOP
add.w #1, D2 ; Increase the value in the register D2 by 1
move.l D3, D0 ; Store the value in the register D3 into data register D0
bra FACTORIZATION_LOOP ; Jump to label FACTORIZATION_LOOP
FACTOR_FOUND:
swap D0
move.w D2, (A1)+
swap D0 ; Swaps the first two and the last two bytes in data register D0
move.w D2, (A1)+ ; Store the value in the register D2 into the memory at the address stored in address register A1. Afterwards increase the address in the register A1 by 2
cmp.w #1, D0
bgt FACTORIZATION_LOOP
cmp.w #1, D0 ; Compare the constant 1 and the value in the register D0
bgt FACTORIZATION_LOOP ; Jump to label FACTORIZATION_LOOP if the value in the register D0 > the constant 1
rts
rts ; Return from the subroutine
START: ; first instruction of program
move.l #numbers, A0
move.l #liste, A1
move.l #anzahl, D1
move.l #numbers, A0 ; Store the address of the variable numbers into address register A0
move.l #liste, A1 ; Store the address of the variable liste into address register A1
move.l #anzahl, D1 ; Store the constant anzahl into data register D1
LOOP:
move.w (A0)+, D0
bsr FACTORIZATION
move.w (A0)+, D0 ; Store the value at the address stored in address register A0 into data register D0. Afterwards increase the address in the register A0 by 2
bsr FACTORIZATION ; Call subroutine FACTORIZATION
sub.l #1, D1
sub.l #1, D1 ; Decrease the value in the register D1 by 1
cmp.l #0, D1
bgt LOOP
cmp.l #0, D1 ; Compare the constant 0 and the value in the register D1
bgt LOOP ; Jump to label LOOP if the value in the register D1 > the constant 0
SIMHALT ; halt simulator
@@ -61,3 +61,4 @@ liste ds.w 20
*~Font size~10~
*~Tab type~1~
*~Tab size~4~