Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Verify the sample codes in The INC, DEC ... Instructions Notes. Submit screen shot of each program. mov esi, value dec byte [esi] The ADD

Verify the sample codes in "The INC, DEC ... Instructions Notes". Submit screen shot of each program. image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

image text in transcribedimage text in transcribed

mov esi, value dec byte [esi] The ADD and SUB Instructions The ADD and SUB instructions are used for performing simple addition/subtraction of binary data in byte, word and doubleword size, i.e., for adding or subtracting 8-bit, 16-bit or 32-bit operands, respectively Syntax The ADD and SUB instructions have the following syntax - ADD/SUB destination, source The ADD/SUB instruction can take place between - Register to register Memory to register Register to memory Register to constant data . . Memory to constant data However, like other instructions, memory-to-memory operations are not possible using ADD/SUB instructions. An ADD or SUB operation sets or clears the overflow and carry flags. Example The following example will ask two digits from the user, store the digits in the EAX and EBX register, respectively, add the values, store the result in a memory location 'res' and finally display the result. %include "ic.inc" segment .data msg1 db "Enter a digit" 0xA,0 lenl equ - msgl msg2 db "Please enter a second digit", 0xA,0 len2 equ -msg2 msg3 db "The sum is: ",0 len3 equ S- msg3 segment .bss numl resb 2 num2 resb 2 res resb 1 section .text global CMAIN CMAIN: write your code here xor eax, eax PRINT STRING msgl GET DEC 1, numl PRINT STRING msgz GET DEC 1, nun2 PRINT STRING nsg3 : moving the first number to eax register and second number to ebx ; and subtracting ascii '' to convert it into a decimal number mov eax, [numi] sub eax, 0 mov ebx, [num21 sub ebx, '0' add eax and ebx add eax, ebx storing the sum in memory location res mov res], eax print the sum PRINT DEC 1, res ret When the above code is compiled and executed, it produces the following result Enter a digit: Please enter a second digit: The sum is: The program with hardcoded variables - tinclude "io.inc segment .data msg db "The sum is: ", 0 segment .bss sum resb 1 section .text CMAIN: write your code here giobal CMAIN mov ebp, esp; or correct debugging xor eax, eax mov eax, 2' sub eax, mov ebx, '5' sub ebx, 0' ; add eax and ebx add eax, ebx storing the sum in memory location sum PRINT STRING msg mov sum,eax ; print the sum PRINT_DEC 1, sum ret When the above code is compiled and executed, it produces the following result - The sum is: The MUL/IMUL Instruction There are two instructions for multiplying binary data. The MUL (Multiply) instruction handles unsigned data and the IMUL (Integer Multiply) handles signed data. Both instructions affect the Carry and Overflow fla Svntax The syntax for the MUL/IMUL instructions is as follows MUL/IMUL multiplier Multiplicand in both cases will be in an accumulator, depending upon the size of the multiplicand and the multiplier and the generated product is also stored in two registers depending upon the size of the operands. Following section explains MUL instructions with three different cases - Sr.No Scenarios When two bytes are multiplied - The multiplicand is in the AL register, and the multiplier is a byte in the memory or in another register. The product is in AX. High-order 8 bits of the product is stored in AH and the low-order 8 bits are stored in AL AL 1x18 Bit Source l= AH AL When two one-word values are multiplied - The multiplicand should be in the AX register, and the multiplier is a word in memory or another register. For example, for an instruction like MUL DX, you must store the multiplier in DX and the multiplicand in AX The resultant product is a doubleword, which will need two registers. The high-order (leftmost) portion gets stored in DX and the lower-order (rightmost) portion gets stored in AX AX | X | 16 Bit Source | = | DX When two doubleword values are multiplied - When two doubleword values are multiplied, the multiplicand should be in EAX and the AX multiplier is a doubleword value stored in memory or in another register. The product 3 generated is stored in the EDX:EAX registers, i.e., the high order 32 bits gets stored in the EDX register and the low order 32-bits are stored in the EAX register EAX | X | 32 Bit Source | | EDX | | EAX Example MOV AL, 10 MOV DL, 25 MUI, DI MOV DL, 0FFH MOV AL, OBEH IMUL DL ; DL=-1 ; AL=-66 Example The following example multiplies 3 with 2, and displays the result %include "ioinc" section .data msg db "The result is: ",0 segment.bss res resb I section .text global CMAIN CMAIN: ;write your code here xor eax, eax mov al,'3 sub al, '0 mov bl, "2 sub bl, 'O' mul bl ; Store results mov [res], al PRINT_STRING msg PRINT_DEC 1, res ret When the above code is compiled and executed, it produces the following result - The result is: The DIV/IDIV Instructions The division operation generates two elements - a quotient and a remainder. In case of multiplication, overflow does not occur because double-length registers are used to keep the product. However, in case of division, overflow may occur. The processor generates an interrupt if overflow occurs The DIV (Divide) instruction is used for unsigned data and the IDIV (Integer Divide) is used for signed data. Syntax The format for the DIV/IDIV instruction DIV/IDIV divisor The dividend is in an accumulator. Both the instructions can work with 8-bit, 16-bit or 32-bit operands. The operation affects all six status flags. Following section explains three cases of division with different operand size Sr.No Scenarios When the divisor is 1 byte- The dividend is assumed to be in the AX register (16 bits). After division, the quotient goes to the AL register and the remainder goes to the AH register 16 bit dividend AX Quotient Remainder AL And AH 8 bit Divisor When the divisor is 1 word The dividend is assumed to be 32 bits long and in the DX:AX registers. The high-order 16 bits are in DX and the low-order 16 bits are in AX. After division, the 16-bit quotient goes to the AX register and the 16-bit remainder goes to the DX register 32 bit dividend DX Quotient Remainder AXAnDX 16 bit Divisor When the divisor is doubleword The dividend is assumed to be 64 bits long and in the EDX:EAX registers. The high- order 32 bits are in EDX and the low-order 32 bits are in EAX. After division, the 32-bit quotient goes to the EAX register and the 32-bit remainder goes to the EDX register. 64 bit dividend Quotient Remainder EDX EAX 32 bit Divisor Example The following example divides 8 with 2. The dividend 8 is stored in the 16-bit AX register and the divisor 2 is stored in the 8-bit BL register. %include "io.inc" section .data msg db "The result is: ",O segment.bss res resb section .text global CMAIN CMAIN: write your code here xor eax, eax mov ax, 8 sub ax, O mov bl, '2 sub bl, 0 div bl mov [res], ax PRINT STRING msg PRINT_DEC 1,res ret When the above code is compiled and executed, it produces the following result The result is: mov esi, value dec byte [esi] The ADD and SUB Instructions The ADD and SUB instructions are used for performing simple addition/subtraction of binary data in byte, word and doubleword size, i.e., for adding or subtracting 8-bit, 16-bit or 32-bit operands, respectively Syntax The ADD and SUB instructions have the following syntax - ADD/SUB destination, source The ADD/SUB instruction can take place between - Register to register Memory to register Register to memory Register to constant data . . Memory to constant data However, like other instructions, memory-to-memory operations are not possible using ADD/SUB instructions. An ADD or SUB operation sets or clears the overflow and carry flags. Example The following example will ask two digits from the user, store the digits in the EAX and EBX register, respectively, add the values, store the result in a memory location 'res' and finally display the result. %include "ic.inc" segment .data msg1 db "Enter a digit" 0xA,0 lenl equ - msgl msg2 db "Please enter a second digit", 0xA,0 len2 equ -msg2 msg3 db "The sum is: ",0 len3 equ S- msg3 segment .bss numl resb 2 num2 resb 2 res resb 1 section .text global CMAIN CMAIN: write your code here xor eax, eax PRINT STRING msgl GET DEC 1, numl PRINT STRING msgz GET DEC 1, nun2 PRINT STRING nsg3 : moving the first number to eax register and second number to ebx ; and subtracting ascii '' to convert it into a decimal number mov eax, [numi] sub eax, 0 mov ebx, [num21 sub ebx, '0' add eax and ebx add eax, ebx storing the sum in memory location res mov res], eax print the sum PRINT DEC 1, res ret When the above code is compiled and executed, it produces the following result Enter a digit: Please enter a second digit: The sum is: The program with hardcoded variables - tinclude "io.inc segment .data msg db "The sum is: ", 0 segment .bss sum resb 1 section .text CMAIN: write your code here giobal CMAIN mov ebp, esp; or correct debugging xor eax, eax mov eax, 2' sub eax, mov ebx, '5' sub ebx, 0' ; add eax and ebx add eax, ebx storing the sum in memory location sum PRINT STRING msg mov sum,eax ; print the sum PRINT_DEC 1, sum ret When the above code is compiled and executed, it produces the following result - The sum is: The MUL/IMUL Instruction There are two instructions for multiplying binary data. The MUL (Multiply) instruction handles unsigned data and the IMUL (Integer Multiply) handles signed data. Both instructions affect the Carry and Overflow fla Svntax The syntax for the MUL/IMUL instructions is as follows MUL/IMUL multiplier Multiplicand in both cases will be in an accumulator, depending upon the size of the multiplicand and the multiplier and the generated product is also stored in two registers depending upon the size of the operands. Following section explains MUL instructions with three different cases - Sr.No Scenarios When two bytes are multiplied - The multiplicand is in the AL register, and the multiplier is a byte in the memory or in another register. The product is in AX. High-order 8 bits of the product is stored in AH and the low-order 8 bits are stored in AL AL 1x18 Bit Source l= AH AL When two one-word values are multiplied - The multiplicand should be in the AX register, and the multiplier is a word in memory or another register. For example, for an instruction like MUL DX, you must store the multiplier in DX and the multiplicand in AX The resultant product is a doubleword, which will need two registers. The high-order (leftmost) portion gets stored in DX and the lower-order (rightmost) portion gets stored in AX AX | X | 16 Bit Source | = | DX When two doubleword values are multiplied - When two doubleword values are multiplied, the multiplicand should be in EAX and the AX multiplier is a doubleword value stored in memory or in another register. The product 3 generated is stored in the EDX:EAX registers, i.e., the high order 32 bits gets stored in the EDX register and the low order 32-bits are stored in the EAX register EAX | X | 32 Bit Source | | EDX | | EAX Example MOV AL, 10 MOV DL, 25 MUI, DI MOV DL, 0FFH MOV AL, OBEH IMUL DL ; DL=-1 ; AL=-66 Example The following example multiplies 3 with 2, and displays the result %include "ioinc" section .data msg db "The result is: ",0 segment.bss res resb I section .text global CMAIN CMAIN: ;write your code here xor eax, eax mov al,'3 sub al, '0 mov bl, "2 sub bl, 'O' mul bl ; Store results mov [res], al PRINT_STRING msg PRINT_DEC 1, res ret When the above code is compiled and executed, it produces the following result - The result is: The DIV/IDIV Instructions The division operation generates two elements - a quotient and a remainder. In case of multiplication, overflow does not occur because double-length registers are used to keep the product. However, in case of division, overflow may occur. The processor generates an interrupt if overflow occurs The DIV (Divide) instruction is used for unsigned data and the IDIV (Integer Divide) is used for signed data. Syntax The format for the DIV/IDIV instruction DIV/IDIV divisor The dividend is in an accumulator. Both the instructions can work with 8-bit, 16-bit or 32-bit operands. The operation affects all six status flags. Following section explains three cases of division with different operand size Sr.No Scenarios When the divisor is 1 byte- The dividend is assumed to be in the AX register (16 bits). After division, the quotient goes to the AL register and the remainder goes to the AH register 16 bit dividend AX Quotient Remainder AL And AH 8 bit Divisor When the divisor is 1 word The dividend is assumed to be 32 bits long and in the DX:AX registers. The high-order 16 bits are in DX and the low-order 16 bits are in AX. After division, the 16-bit quotient goes to the AX register and the 16-bit remainder goes to the DX register 32 bit dividend DX Quotient Remainder AXAnDX 16 bit Divisor When the divisor is doubleword The dividend is assumed to be 64 bits long and in the EDX:EAX registers. The high- order 32 bits are in EDX and the low-order 32 bits are in EAX. After division, the 32-bit quotient goes to the EAX register and the 32-bit remainder goes to the EDX register. 64 bit dividend Quotient Remainder EDX EAX 32 bit Divisor Example The following example divides 8 with 2. The dividend 8 is stored in the 16-bit AX register and the divisor 2 is stored in the 8-bit BL register. %include "io.inc" section .data msg db "The result is: ",O segment.bss res resb section .text global CMAIN CMAIN: write your code here xor eax, eax mov ax, 8 sub ax, O mov bl, '2 sub bl, 0 div bl mov [res], ax PRINT STRING msg PRINT_DEC 1,res ret When the above code is compiled and executed, it produces the following result The result is

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 22nd European Conference Adbis 2018 Budapest Hungary September 2 5 2018 Proceedings Lncs 11019

Authors: Andras Benczur ,Bernhard Thalheim ,Tomas Horvath

1st Edition

3319983970, 978-3319983974

More Books

Students also viewed these Databases questions

Question

What security risks was GMA exposed to with their B2B solution?

Answered: 1 week ago