Write an assembly program to implement the following. while X > 0 if X != 3 AND
ID: 3912851 • Letter: W
Question
Write an assembly program to implement the following.
while X > 0
if X != 3 AND (X < A OR X > B)
X = X – 2
else
X = X – 1
end while
Use short-circuit evaluation
Assume that A, B, and X are 32-bit signed integers variables
Assume that A=5, B=8, and X=13
Explanation / Answer
Program: File Name: file.asm ; Include files INCLUDE Irvine32.inc ;Set model .386 .model flat,stdcall ;set value .stack 4096 ;DEfine exit process ExitProcess proto,dwExitCode:dword ;Define data section .data ;Declare A A word 5 ;Declare B B word 8 ;Declare X X word 13 ;Define message msg BYTE "X value after each iteration:", 0ah, 0dh ;Code section .code ;Define main main proc ;Set eax register mov eax, 0 ;Load X value mov ax,X ;Load msg mov edx, OFFSET msg ;Print statement call WriteString ;While Loop L1: ;Check X>0 cmp ax, 0 ;If not jump to end while jbe endWhile ;Check x!=3 cmp ax, 3 ;If X=3, jump to else jz L3 ;Compare XB cmp ax, B ;If false, jump to L3 jb L3 ;If block L2: ;Decrease 2 from X sub ax, 2 ;Go to next jmp next ;Else block L3: ;Decrease 1 from X sub ax, 1 ;Next next: ;New line call CrLf ;Print X value call WriteDec ;Jump to start of while loop L1 ;End of while loop endWhile: ;Save X value mov X, ax ;new line call Crlf ;Wait call WaitMsg ;Stop program invoke ExitProcess,0 ;end of main procedure main endp ;Stop program end mainRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.