From a3ab855be333f9cd2ece46e4e2066921659c840b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=B6gele?= Date: Tue, 23 Jun 2015 14:12:19 +0200 Subject: [PATCH] Cross my hart and hope to fly, stick a cupcake in my eye --- Aufgabe4_Vögele_Wörner.X68 | 107 +++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 52 deletions(-) diff --git a/Aufgabe4_Vögele_Wörner.X68 b/Aufgabe4_Vögele_Wörner.X68 index 5bbf30d..893fde0 100644 --- a/Aufgabe4_Vögele_Wörner.X68 +++ b/Aufgabe4_Vögele_Wörner.X68 @@ -1,52 +1,55 @@ -*----------------------------------------------------------- -* Title : Prime number calculator -* Written by : Manuel Voegele and Simon Woerner -* Date : 2015-06-23 -* Description: Calculates the prime numbers from 3 to 100 -*----------------------------------------------------------- - ORG $3000 -START: ; first instruction of program - -* Put program code here - - move.w #n_start, D0 - move.l #list, A0 - -LOOP_CHECK_PRIME: - move.w #2, D1 - -LOOP_CHECK_NUMBER: - move.w D0, D2 - divu D1, D2 - clr.w D2 - swap D2 - cmp.w #0, D2 - beq LOOP_FOOT_NEXT_PRIME - add.w #1, D1 - move.w D1, D2 - mulu D2, D2 - cmp.w D0, D2 - ble LOOP_CHECK_NUMBER - - move.w D0, (A0)+ - -LOOP_FOOT_NEXT_PRIME: - add.w #1, D0 - cmp #n_end, D0 - ble LOOP_CHECK_PRIME - - SIMHALT ; halt simulator - -* Put variables and constants here - -n_start EQU 3 -n_end EQU 100 - -list ds.w 100 - - END START ; last line of source - -*~Font name~Courier New~ -*~Font size~10~ -*~Tab type~1~ -*~Tab size~4~ +*----------------------------------------------------------- +* Title : Prime number calculator +* Written by : Manuel Voegele and Simon Woerner +* Date : 2015-06-23 +* Description: Calculates the prime numbers from 3 to 100 +*----------------------------------------------------------- + ORG $3000 ; Start at address 3000 +START: ; first instruction of program + +* Put program code here + + move.w #n_start, D0 ; Store the constant n_start into data register D0 + move.l #list, A0 ; Store the address of the variable list into address register A0 + +LOOP_CHECK_PRIME: + move.w #2, D1 ; Store the constant 2 into data register D1 + +LOOP_CHECK_NUMBER: + move.w D0, D2 ; Store the value in the register D0 into data register 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 + clr.w D2 ; Clear data register D2 + swap D2 ; Swaps the first two and the last two bytes in data register D2 + cmp.w #0, D2 ; Compare the constant 0 and the value in the register D2 + beq LOOP_FOOT_NEXT_PRIME ; Jump to label LOOP_FOOT_NEXT_PRIME if the value in the register D2 == the constant 0 + + add.w #1, D1 ; Increase the value in the register D1 by 1 + move.w D1, D2 ; Store the value in the register D1 into data register D2 + 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 + ble LOOP_CHECK_NUMBER ; Jump to label LOOP_CHECK_NUMBER if the value in the register D2 <= the value in the register D0 + + 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 + +LOOP_FOOT_NEXT_PRIME: + add.w #1, D0 ; Increase the value in the register D0 by 1 + cmp #n_end, D0 + ble LOOP_CHECK_PRIME ; Jump to label LOOP_CHECK_PRIME if the value in the register D0 <= the constant n_end + + SIMHALT ; halt simulator + +* Put variables and constants here + +n_start EQU 3 +n_end EQU 100 + +list ds.w 100 + + END START ; last line of source + +*~Font name~Courier New~ +*~Font size~10~ +*~Tab type~1~ +*~Tab size~4~ +