Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Intel Assembly language programming Complete the following Intel assembly langua

ID: 3812840 • Letter: I

Question

Intel Assembly language programming

Complete the following Intel assembly language program which determines whether the byte sized operand stored in memory location 'number' is prime or not. The program will write the value of 0 into the memory location 'answer' if the number is not prime, otherwise the initial value of '1' will be left unmodified (indicating that the number is prime). The program makes use of the DIV instruction to determine the value of quotient and remainder when dividing the number by 2,3,4,... (number -1) .


section .data

; put your data in this section using

; db , dw, dd directions

number db 5

answer db 1 ; 1 means number is prime, 0 means number is not prime section .bss

; put UNINITIALIZED data here using

section .text

global _start

_start:

mov esi, number ; get the offset of number into esi

keith: mov eax, 0 ; clear the entire eax register

mov al, [esi] ; get the number from memory into al

mov dl, al ; put it inside dl as well

mov bl, 2 ; bl holds each divisor starting from 2

loopy: div bl ; ax / bl with quot in al and rem in ah

and ax, 1111111100000000b ; isolate the rem in ah with a AND mask

; to determine whether the remainder is 0

; YOU COMPLETE THE REST OF THE CODE





HINT: The program is to implement the following high-level

pseudocode:

prime = true ;

divisor = 2 ;

while ( divisor < number )

{

if ( the remainder of number / divisor is 0 )

{

prime = false ; // we found a divisor which evenly divides number

} // so therefore number cannot be prime

divisor = divisor + 1 ; // check the next divisor and keep looping

}

Explanation / Answer

section .data
; put your data in this section using
; db , dw, dd directions

number db 5
answer db 1 ; 1 means number is prime, 0 means number is not prime section .bss

; put UNINITIALIZED data here using

section .text
global _start

_start:
mov esi, number ; get the offset of number into esi
keith: mov eax, 0 ; clear the entire eax register
mov al, [esi] ; get the number from memory into al
mov dl, al ; put it inside dl as well
mov bl, 2 ; bl holds each divisor starting from 2
loopy: div bl ; ax / bl with quot in al and rem in ah
and ax, 1111111100000000b ; isolate the rem in ah with a AND mask
cmp ah, 0; to determine whether the remainder is 0

jz loop1; to jump to loop1 if remainder is zero
inc bl; otherwise divisor get incremented

jne loopy;loopy loop continued until divisor < number
jmp exit;exit from loopy
loop1:
mov ecx,0;
mov ecx,answer;moving 0 to answer when number is not prime
jmp exit;exit from loop1

exit:

mov eax,1 ;system call number (sys_exit)

int 0x80 ;call kernel

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote