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

Use a nasm program that uses two subprograms void writeString(String str, int st

ID: 3701282 • Letter: U

Question

Use a nasm program that uses two subprograms

void writeString(String str, int strLen)
(Copy this subprogram down here and paste it in your code first) ; hello world program section .data msg1 db 'hello world; passing two parameters using stack!!', 10 msg1_len equ $-msg1 msg2 db 'it is real fun learning assembly language', 10 msg2_len equ $-msg2
section .bss
section .text global _start _start:
push msg1 push msg1_len call writeString
push msg2 push msg2_len call writeString
mov eax, 1 mov ebx, 0 int 80h
;;; void writeString(String str, int strLen) ;; function: outputs characters at str (strLen of them) to stdout ;; recieves: str, a String address, at which a string of length, strLen, is stored. ;; returns: nothing. writeString: push ebp ; sets basepointer mov ebp, esp
mov edx, [ebp+8] mov ecx, [ebp+12] mov eax, 4 mov ebx, 1 int 80h
pop ebp ; returns ebp to previous point. ret 8 ———————————- end of the subprogram code ————!!

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
Use a nasm program that uses two subprograms

void writeString(String str, int strLen)
(Copy this subprogram down here and paste it in your code first) ; hello world program section .data msg1 db 'hello world; passing two parameters using stack!!', 10 msg1_len equ $-msg1 msg2 db 'it is real fun learning assembly language', 10 msg2_len equ $-msg2
section .bss
section .text global _start _start:
push msg1 push msg1_len call writeString
push msg2 push msg2_len call writeString
mov eax, 1 mov ebx, 0 int 80h
;;; void writeString(String str, int strLen) ;; function: outputs characters at str (strLen of them) to stdout ;; recieves: str, a String address, at which a string of length, strLen, is stored. ;; returns: nothing. writeString: push ebp ; sets basepointer mov ebp, esp
mov edx, [ebp+8] mov ecx, [ebp+12] mov eax, 4 mov ebx, 1 int 80h
pop ebp ; returns ebp to previous point. ret 8 ———————————- end of the subprogram code ————!!

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
Use a nasm program that uses two subprograms

void writeString(String str, int strLen)
(Copy this subprogram down here and paste it in your code first) ; hello world program section .data msg1 db 'hello world; passing two parameters using stack!!', 10 msg1_len equ $-msg1 msg2 db 'it is real fun learning assembly language', 10 msg2_len equ $-msg2
section .bss
section .text global _start _start:
push msg1 push msg1_len call writeString
push msg2 push msg2_len call writeString
mov eax, 1 mov ebx, 0 int 80h
;;; void writeString(String str, int strLen) ;; function: outputs characters at str (strLen of them) to stdout ;; recieves: str, a String address, at which a string of length, strLen, is stored. ;; returns: nothing. writeString: push ebp ; sets basepointer mov ebp, esp
mov edx, [ebp+8] mov ecx, [ebp+12] mov eax, 4 mov ebx, 1 int 80h
pop ebp ; returns ebp to previous point. ret 8 ; hello world program section .data msg1 db 'hello world; passing two parameters using stack!!', 10 msg1_len equ $-msg1 msg2 db 'it is real fun learning assembly language', 10 msg2_len equ $-msg2
section .bss
section .text global _start _start:
push msg1 push msg1_len call writeString
push msg2 push msg2_len call writeString
mov eax, 1 mov ebx, 0 int 80h
;;; void writeString(String str, int strLen) ;; function: outputs characters at str (strLen of them) to stdout ;; recieves: str, a String address, at which a string of length, strLen, is stored. ;; returns: nothing. writeString: push ebp ; sets basepointer mov ebp, esp
mov edx, [ebp+8] mov ecx, [ebp+12] mov eax, 4 mov ebx, 1 int 80h
pop ebp ; returns ebp to previous point. ret 8 ———————————- end of the subprogram code ————!!

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

Answer:

Using nasm program:

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”