Use a nasm program that uses two subprograms void writeString(String str, int st
ID: 3699888 • Letter: U
Question
Use a nasm program that uses two subprograms
void writeString(String str, int strLen)
(You already have the code for this subprogram. Copy and paste it in your code first)
int isDivisible(int number1, int number2)
divides number1 by number2.
If it is fully divisible returns a 1; else, returns a 0
It is customary to return the value in eax register
Write the main program in which you will create two variables
num1 = 125
num2 = 6
Call the isDivisible subprogram with these two values
Check the return value in eax
Based on the return value, print in standard output either one of these two messages
“Yes! It is divisible”
“No! it is not NOT divisible”
Use the writeString method to print the message
Explanation / Answer
main:
mov ebx, 125
mov ecx, 6
push ebx ; push both the numbers onto stack for isDivisible to consume
push ecx
call isDivisible
cmp eax, 1 ; if return value in eax 1
jne ZERO ; if not print msg0
push msg1 ; print msg1
push 21
call writeString
jmp END
ZERO:
push msg0
push 27
call writeString
END:
mov rax, 0x02000001 ; system call for exit
xor rdi, rdi ; exit code 0
syscall
msg1 db “Yes! It is divisible”
msg0 db “No! it is not NOT divisible”
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.