Answer to Question #333358 in Assembler for junior

Question #333358
  • Write the assembly language code fragment that corresponds with the following high level language code fragment. You will need to use the SUB (subtract) instruction.

If (A>B) OR (B<C) then

           A = A + C

Else

           B = C - A


  • Write the assembly fragment to perform the following:

For x = 1 to 10

A = A + x

Next x


  • Write the assembly code for the following high-level pseudo code:

if ((a>=b) AND (b==c)) OR (a<=c) then

a = b + c

else

            a = b - c




1
Expert's answer
2022-04-27T18:25:21-0400
include Irvine32.inc
.data
 
varA DWORD 1
varB DWORD 2
varC DWORD 2
varX DWORD 1

.code
main proc
Task1:
; If (A>B) OR (B<C) then
;    A = A + C
; Else
;    B = C - A

    mov eax,varA
    mov ebx,varB
    mov ecx,varC

    cmp eax,ebx
    jg L1            ;If (A>B)->L1
    cmp ebx,ecx        ;if (B<C)->L1
    jl L1
;else
    sub ecx, eax    ;  C - A
    mov varB, ecx    ;  B = C - A
    jmp Task2
L1:
    add varA, ecx    ; A = A + C

Task2:
; For x = 1 to 10
; A = A + x
; Next x
    mov eax, varA
for_:
    add eax,varX    ; A = A + x
    inc varX        ; next x
    cmp varX,10
    jle for_
    mov varA,eax

Task3:
; if ((a>=b) AND (b==c)) OR (a<=c) then
;    a = b + c
; else
;    a = b - c
    mov eax,varA
    mov ebx,varB
    mov ecx,varC

    cmp eax,ebx        
    jge L2            ; if ((a>=b)->L2
    cmp eax, ecx    
    jle res1        ; if (a<=c)->result_1
    jmp res2

L2:
    cmp ebx,ecx
    je res1            ; if(b==c)->res1
    cmp eax, ecx    ;  
    jle res1        ; if (a<=c)->res1
    jmp res2
res1:
    add ebx,ecx
    mov varA,ebx    ;  a = b + c
    jmp _exit
res2:
    sub ebx,ecx
    mov varA, ebx    ;   a = b - c

_exit:
    invoke ExitProcess,0 ; Exit program
main endp
end main

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS