*----------------------------------------------------------- * Title : prime factorization * Written by : Manuel Voegele and Simon Woerner * Date : 2015-06-09 * Description: RTFT *----------------------------------------------------------- ORG $3000 ; Start at address 3000 * Put program code here FACTORIZATION: move.l #2, D2 ; Store the constant 2 into data register D2 FACTORIZATION_LOOP: 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 ; 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 ; 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 ; 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 ; Return from the subroutine START: ; first instruction of program 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 ; 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 ; Decrease the value in the register D1 by 1 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 * Put variables and constants here numbers dc.w 42,6930,997 anzahl EQU 3 liste ds.w 20 END START ; last line of source *~Font name~Courier New~ *~Font size~10~ *~Tab type~1~ *~Tab size~4~