Cross my hart and hope to fly, stick a cupcake in my eye
This commit is contained in:
@@ -4,36 +4,38 @@
|
||||
* Date : 2015-06-23
|
||||
* Description: Calculates the prime numbers from 3 to 100
|
||||
*-----------------------------------------------------------
|
||||
ORG $3000
|
||||
ORG $3000 ; Start at address 3000
|
||||
START: ; first instruction of program
|
||||
|
||||
* Put program code here
|
||||
|
||||
move.w #n_start, D0
|
||||
move.l #list, A0
|
||||
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
|
||||
move.w #2, D1 ; Store the constant 2 into data register 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, D2 ; Store the value in the register D0 into data register D2
|
||||
|
||||
move.w D0, (A0)+
|
||||
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
|
||||
add.w #1, D0 ; Increase the value in the register D0 by 1
|
||||
cmp #n_end, D0
|
||||
ble LOOP_CHECK_PRIME
|
||||
ble LOOP_CHECK_PRIME ; Jump to label LOOP_CHECK_PRIME if the value in the register D0 <= the constant n_end
|
||||
|
||||
SIMHALT ; halt simulator
|
||||
|
||||
@@ -50,3 +52,4 @@ list ds.w 100
|
||||
*~Font size~10~
|
||||
*~Tab type~1~
|
||||
*~Tab size~4~
|
||||
|
||||
|
||||
Reference in New Issue
Block a user