Cross my hart and hope to fly, stick a cupcake in my eye

This commit is contained in:
2015-06-23 14:12:19 +02:00
parent 0cfd8a82ed
commit a3ab855be3

View File

@@ -1,52 +1,55 @@
*----------------------------------------------------------- *-----------------------------------------------------------
* Title : Prime number calculator * Title : Prime number calculator
* Written by : Manuel Voegele and Simon Woerner * Written by : Manuel Voegele and Simon Woerner
* Date : 2015-06-23 * Date : 2015-06-23
* Description: Calculates the prime numbers from 3 to 100 * Description: Calculates the prime numbers from 3 to 100
*----------------------------------------------------------- *-----------------------------------------------------------
ORG $3000 ORG $3000 ; Start at address 3000
START: ; first instruction of program START: ; first instruction of program
* Put program code here * Put program code here
move.w #n_start, D0 move.w #n_start, D0 ; Store the constant n_start into data register D0
move.l #list, A0 move.l #list, A0 ; Store the address of the variable list into address register A0
LOOP_CHECK_PRIME: LOOP_CHECK_PRIME:
move.w #2, D1 move.w #2, D1 ; Store the constant 2 into data register D1
LOOP_CHECK_NUMBER: LOOP_CHECK_NUMBER:
move.w D0, D2 move.w D0, D2 ; Store the value in the register D0 into data register D2
divu D1, D2
clr.w D2 divu D1, D2 ; Divide the value in the register D1 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 D2
swap D2 clr.w D2 ; Clear data register D2
cmp.w #0, D2 swap D2 ; Swaps the first two and the last two bytes in data register D2
beq LOOP_FOOT_NEXT_PRIME cmp.w #0, D2 ; Compare the constant 0 and the value in the register D2
add.w #1, D1 beq LOOP_FOOT_NEXT_PRIME ; Jump to label LOOP_FOOT_NEXT_PRIME if the value in the register D2 == the constant 0
move.w D1, D2
mulu D2, D2 add.w #1, D1 ; Increase the value in the register D1 by 1
cmp.w D0, D2 move.w D1, D2 ; Store the value in the register D1 into data register D2
ble LOOP_CHECK_NUMBER mulu D2, D2 ; Calculate the square of the value in the register D2 and store the result in data register D2
cmp.w D0, D2 ; Compare the value in the register D0 and the value in the register D2
move.w D0, (A0)+ ble LOOP_CHECK_NUMBER ; Jump to label LOOP_CHECK_NUMBER if the value in the register D2 <= the value in the register D0
LOOP_FOOT_NEXT_PRIME: move.w D0, (A0)+ ; Store the value in the register D0 into the memory at the address stored in address register A0. Afterwards increase the address in the register A0 by 2
add.w #1, D0
cmp #n_end, D0 LOOP_FOOT_NEXT_PRIME:
ble LOOP_CHECK_PRIME add.w #1, D0 ; Increase the value in the register D0 by 1
cmp #n_end, D0
SIMHALT ; halt simulator ble LOOP_CHECK_PRIME ; Jump to label LOOP_CHECK_PRIME if the value in the register D0 <= the constant n_end
* Put variables and constants here SIMHALT ; halt simulator
n_start EQU 3 * Put variables and constants here
n_end EQU 100
n_start EQU 3
list ds.w 100 n_end EQU 100
END START ; last line of source list ds.w 100
*~Font name~Courier New~ END START ; last line of source
*~Font size~10~
*~Tab type~1~ *~Font name~Courier New~
*~Tab size~4~ *~Font size~10~
*~Tab type~1~
*~Tab size~4~