Write assembly language code segment for the following assignment statement. Ass
ID: 3571222 • Letter: W
Question
Write assembly language code segment for the following assignment statement. Assume that the variables var1, var2, var3, and var4 are defined as SDWORD integers: var4 = (var1 * -5)/(-var2 % var3) Code instructions that implement the following pseudocode using conditional jump instructions. Do not use the .IF directive. Assume that variables are defined as SDWORD integers: if(val1 > val2 && val2 > eax) mov ebx, 1; else mov ebx, 2; What is the difference between JMP and CALL instructions? Assume 32-bit mode. For example what is the difference between using the following two instructions: JMP example CALL example Where, example is a label in the code segment. Assuming the following data definitions balance SWORD 10 DUP(?) max SWORD? len SWORD ? Write Assembly Language code fragment to implement the following C++ like statements: max = balance[0]; for(int I = 1; iExplanation / Answer
1.Ans
.data
var1 BYTE 20h
var2 WORD 1000h
var3 DWORD ?
var4 BYTE 10, 20, 30, 40, 50
.data
VAR4 SDWORD ?
VAR1 SDWORD 26
VAR2 SDWORD 30
VAR3 SDWORD 40
.code;
MOV VAR1 -5
MOV RES VAR1
MOV var2 var3
MOV res1 var2
mov res1 res
2.
cmp var1 var2;
cmp val2 eax;
mov ebx,1;
jbe next ; quit if false
mov X,1 ; both are true
next:
iv) Ans
.data
txt1: .asciiz "Please enter apositive integer (negative integer to exit) : "
txt2: .asciiz " The maximum value is : "
.text
.globl main
main:
addi $s0, $zero, 0
loop:
la $a0, txt1
li $v0, 4
syscall
li $v0, 5
syscall
bltz $v0, average
add $s0, $v0, 0
add $t0, $t0, 1
add $t3, $t3, $s0
beq $t0, 1, first
blt $s0, $t1, min
bgt $s0, $t2, max
first:
add $t1, $s0, 0
add $t2, $s0, 0
j loop
j loop
max:
add $t2, $s0, 0
j loop
print:
la $a0, txt2
li $v0, 4
syscall
exit:
li $v0, 10
syscall
iii)Ans
section .text
global _start ;must be declared for using gcc
_start: ;tell linker entry point
mov ecx, [num1]
cmp ecx, [num2]
jg check_third_num
mov ecx, [num2]
check_third_num:
cmp ecx, [num3]
jg _exit
mov ecx, [num3]
_exit:
mov [largest], ecx
mov ecx,msg
mov edx, len
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov ecx,largest
mov edx, 2
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax, 1
int 80h
section .data
msg db "The largest digit is: ", 0xA,0xD
len equ $- msg
num1 dd '47'
num2 dd '22'
num3 dd '31'
segment .bss
largest resb 2
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.