Question: [ ORG 0 x 2 0 0 0 ] ; Define starting point jmp start ; Jump to start num 1 : dw 6 ,
ORG x ; Define starting point
jmp start ; Jump to start
num: dw ; Array of numbers to check
prime: dw ; Array to store prime numbers up to primes
start:
mov si ; Initialize index SI to
mov di ; Initialize index for the prime array DI
mov bx ; Start divisor
mov dx
checknextnum:
cmp si ; Compare SI index with end of num array
jge Haltprogram ; If SI halt the program
; Load the current number into AX
mov axnum si
push bx ; Save BX divisor register
push dx ; Save DX remainder register
; Call prime check subroutine
call checkprime
pop dx ; Restore DX
pop bx ; Restore BX
; Increment index SI
add si ; Move to next number in num array each number is bytes
jmp checknextnum ; Continue to the next number
Haltprogram:
mov axxC ; DOS interrupt to terminate the program
int x ; Terminate the program with return code
checkprime:
cmp ax ; If the number is less than it's not prime
jl notprime ; Jump if less than not prime
mov bx ; Set divisor to
primeloop:
push ax
; Divide AX by BX result in AX remainder in DX
div bx ; AX AX BX DX AX BX
pop ax
cmp dx ; If remainder is it's not prime
je notprime ; If remainder is it's not prime
inc bx ; Increment divisor
cmp bx ax ; If divisor the original number, it's prime
jl primeloop ; If divisor is less than the original number, continue loop
; If we are here, the number is prime
mov prime di ax ; Store the prime number in the prime array primedi
add di ; Increment the prime array index DI by since each entry is bytes
ret
notprime:
ret ; Return from prime check subroutine
my assembly code is not working properly, i need help fixing it My teacher says stack must be used in code.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
