New Semester
Started
Get
50% OFF
Study Help!
--h --m --s
Claim Now
Question Answers
Textbooks
Find textbooks, questions and answers
Oops, something went wrong!
Change your search query and then try again
S
Books
FREE
Study Help
Expert Questions
Accounting
General Management
Mathematics
Finance
Organizational Behaviour
Law
Physics
Operating System
Management Leadership
Sociology
Programming
Marketing
Database
Computer Network
Economics
Textbooks Solutions
Accounting
Managerial Accounting
Management Leadership
Cost Accounting
Statistics
Business Law
Corporate Finance
Finance
Economics
Auditing
Tutors
Online Tutors
Find a Tutor
Hire a Tutor
Become a Tutor
AI Tutor
AI Study Planner
NEW
Sell Books
Search
Search
Sign In
Register
study help
business
implementing programming languages
Assembly Language For X86 Processors 7th Edition Kip Irvine - Solutions
2. (True/False): Arrays are passed by reference to avoid copying them onto the stack.
1. (True/False): A subroutine’s stack frame always contains the caller’s return address and the subroutine’s local variables.
Extend the AddPacked procedure from Section 7.6.1 so that it adds two packed decimal integers of arbitrary size (both lengths must be the same). Write a test program that passes AddPacked several pairs of integers: 4-byte, 8-byte, and 16-byte. We suggest that you use the following registers to pass
Write a procedure named BitwiseMultiply that multiplies any unsigned 32-bit integer by EAX, using only shifting and addition. Pass the integer to the procedure in the EBX register, and return the product in the EAX register. Write a short test program that calls the procedure and displays the
The greatest common divisor (GCD) of two integers is the largest integer that will evenly divide both integers. The GCD algorithm involves integer division in a loop, described by the following pseudocode:int GCD(int x, int y){x = abs(x) // absolute value y = abs(y)do {int n = x % y x = y y = n}
Write a program that generates all prime numbers between 2 and 1000, using the Sieve of Eratosthenes method. You can find many articles that describe the method for finding primes in this manner on the Internet. Display all the prime values.
Write a procedure that performs simple encryption by rotating each plaintext byte a varying number of positions in different directions. For example, in the following array that represents the encryption key, a negative value indicates a rotation to the left and a positive value indicates a
Write a procedure named PackedToAsc that converts a 4-byte packed decimal integer to a string of ASCII decimal digits. Pass the packed integer and the address of a buffer holding the ASCII digits to the procedure. Write a short test program that passes at least 5 packed decimal integers to your
Create a procedure named Extended_Sub that subtracts two binary integers of arbitrary size.The storage size of the two integers must be the same, and their size must be a multiple of 32 bits. Write a test program that passes several pairs of integers, each at least 10 bytes long.
Write a procedure named WriteScaled that outputs a decimal ASCII number with an implied decimal point. Suppose the following number were defined as follows, where DECIMAL_OFFSET indicates that the decimal point must be inserted five positions from the right side of the number:DECIMAL_OFFSET =
16. Challenge: Using only SAR, ADD, and XOR instructions (but no conditional jumps), write code that calculates the absolute value of the signed integer in the EAX register. Hints: A number can be negated by adding 1 to it and then forming its one’s complement. Also, if you XOR an integer with
15. Challenge: Using only SUB, MOV, and AND instructions, show how to calculate x = n mod y, assuming that you are given the values of n and y. You can assume that n is any 32-bit unsigned integer, and y is a power of 2.
14. Challenge: Suppose AX contains 0072h and the Auxiliary Carry flag is set as a result of adding two unknown ASCII decimal digits. Use the Intel 64 and IA-32 Instruction Set Reference to determine what output the AAA instruction would produce. Explain your answer.
13. Write a procedure that displays an unsigned 8-bit binary value in decimal format. Pass the binary value in AL. The input range is limited to 0 to 99, decimal. The only procedure you can call from the book’s link library is WriteChar. The procedure should contain approximately eight
12. Implement the following C++ expression in assembly language, using 32-bit signed operands:val1 = (val2 / val3) * (val1 + val2)
11. Implement the following C++ expression in assembly language, using 32-bit unsigned operands:val1 = (val2 * val3) / (val4 - 3)
10. Write instructions that divide 276 by 10 and store the result in a 16-bit variable val1.
9. Write instructions that multiply 5 by 3 and store the result in a 16-bit variable val1.
8. Write a sequence of instructions that shift three memory words to the left by 1 bit position.Use the following test data:wordArray WORD 810Dh, 0C064h,93ABh
7. Write a sequence of instructions that shift three memory bytes to the right by 1 bit position.Use the following test data:byteArray BYTE 81h,20h,33h
6. Write a single SHLD instruction that shifts the highest bit of the AX register into the lowest bit position of DX and shifts DX one bit to the left.
5. Write a single rotate instruction that exchanges the high and low halves of the DL register.
4. Write a logical shift instruction that divides EBX by 4.
3. Write a logical shift instruction that multiplies the contents of EAX by 16.
2. Suppose the instruction set contained no rotate instructions. Show how you would use SHR and a conditional jump instruction to rotate the contents of the AL register 1 bit to the right.
1. Write a sequence of shift instructions that cause AX to be sign-extended into EAX. In other words, the sign bit of AX is copied into the upper 16 bits of EAX. Do not use the CWD instruction.
10. What will be the hexadecimal contents of RAX after the following instructions execute in 64-bit mode?.data multiplicand QWORD 0001020304050000h.code imul rax,multiplicand, 4
9. The following program is supposed to subtract val2 from val1. Find and correct all logic errors (CLC clears the Carry flag):.data val1 QWORD 20403004362047A1h val2 QWORD 055210304A2630B2h result QWORD 0.code mov cx,8 ; loop counter mov esi,val1 ; set index to start mov edi,val2 clc ; clear Carry
8. Describe the output when the following code executes in 64-bit mode:.data dividend_hi QWORD 00000108h dividend_lo QWORD 33300020h divisor QWORD 00000100h.code mov rdx,dividend_hi mov rax,dividend_lo div divisor
7. What will be the contents of BX after the following instructions execute?mov bx,5 stc mov ax,60h adc bx,ax
6. What will be the contents of AX and DX after the following operation?mov ax,4000h mov dx,500h mov bx,10h div bx
5. What will be the contents of EAX and EDX after the following operation?mov eax,123400h mov edx,0 mov ebx,10h div ebx
4. What will be the contents of AX after the following operation?mov ax,63h mov bl,10h div bl
3. What will be the contents of AX and DX after the following operation?mov dx,0 mov ax,222h mov cx,100h mul cx
2. In the following code sequence, show the value of AL after each shift or rotate instruction has executed:mov al,0D4h ror al,3 ; a.mov al,0D4h rol al,7 ; b.stc mov al,0D4h rcl al,1 ; c.stc mov al,0D4h rcr al,3 ; d.
1. In the following code sequence, show the value of AL after each shift or rotate instruction has executed:mov al,0D4h shr al,1 ; a.mov al,0D4h sar al,1 ; b.mov al,0D4h sar al,4 ; c.mov al,0D4h rol al,1 ; d.
3. When adding two packed decimal integers of length n bytes, how many storage bytes must be reserved for the sum?
2. Under what circumstances does DAS instruction set the Carry flag? Give an example.
1. Under what circumstances does DAA instruction set the Carry flag? Give an example.
4. Write a single instruction that converts an unsigned binary integer in AX to unpacked decimal.
3. Write a two-instruction sequence that converts a two-digit ASCII decimal number in AX to binary.
2. Write a single instruction that converts a two-digit ASCII decimal integer in AX to unpacked decimal format.
1. Write a single instruction that converts a two-digit unpacked decimal integer in AX to ASCII decimal.
5. What will be the contents of DX after the following instructions execute (STC sets the Carry flag)?mov dx,5 stc ; set Carry flag mov ax,10h adc dx,ax
4. What will be the values of EDX:EAX after the following instructions execute?mov edx,100h mov eax,80000000h sub eax,90000000h sbb edx,0
3. What will be the values of EDX:EAX after the following instructions execute?mov edx,10h mov eax,0A0000000h add eax,20000000h adc edx,0
2. Describe the SBB instruction.
1. Describe the ADC instruction.
7. Show an example of sign extension before calling the IDIV instruction with a 16-bit operand.
6. When BL is the operand in a MUL instruction, which registers hold the product?
5. When BX is the operand in a DIV instruction, which register holds the quotient?
4. When EBX is the operand in a DIV instruction, which register holds the quotient?
3. What has to happen in order for the one-operand IMUL to set the Carry and Overflow flags?
2. How is the one-operand IMUL instruction different from MUL in the way it generates a multiplication product?
1. Explain why overflow cannot occur when the MUL and one-operand IMUL instructions execute.
4. The time stamp field of a file directory entry uses bits 0 through 4 for the seconds, bits 5 through 10 for the minutes, and bits 11 through 15 for the hours. Write instructions that extract the minutes and copy the value to a byte variable named bMinutes.
3. What change would you make to the BinToAsc procedure in Section 7.2.3 in order to display the binary bits in reverse order?
2. Write assembly language instructions that calculate EAX * 21 using binary multiplication.
1. Write assembly language instructions that calculate EAX * 24 using binary multiplication.
6. Challenge: One way to calculate the parity of a 32-bit number in EAX is to use a loop that shifts each bit into the Carry flag and accumulates a count of the number of times the Carry flag was set. Write a code that does this, and set the Parity flag accordingly.
5. Challenge: Write a series of instructions that shift the lowest bit of AX into the highest bit of BX without using the SHRD instruction. Next, perform the same operation using SHRD.
4. What happens to the Carry flag when the SHR AX,1 instruction is executed?
3. Which instruction performs the following operation (CF = Carry flag)?Before: CF,AL = 1 11010101 After: CF,AL = 1 10101011
2. Which instruction shifts each bit to the right, copies the lowest bit into the Carry flag, and copies the Carry flag into the highest bit position?
1. Which instruction shifts each bit in an operand to the left and copies the highest bit into both the Carry flag and the lowest bit position?
Data transmission systems and file subsystems often use a form of error detection that relies on calculating the parity (even or odd) of blocks of data. Your task is to create a procedure that returns True in the EAX register if the bytes in an array contain even parity, or False if the parity is
Banks use a Personal Identification Number (PIN) to uniquely identify each customer. Let us assume that our bank has a specified range of acceptable values for each digit in its customers’5-digit PINs. The table shown below contains the acceptable ranges, where digits are numbered from left to
Revise the encryption program in Section 6.3.4 in the following manner: Create an encryption key consisting of multiple characters. Use this key to encrypt and decrypt the plaintext by XORing each character of the key against a corresponding byte in the message. Repeat the key as many times as
Write a program that randomly chooses among three different colors for displaying text on the screen. Use a loop to display 20 lines of text, each with a randomly chosen color. The probabilities for each color are to be as follows: white 30%, blue 10%, green 60%.Suggestion: Generate a random
Continue the solution program from Exercise 5 by implementing the following procedures:• AND_op: Prompt the user for two hexadecimal integers. AND them together and display the result in hexadecimal.• OR_op: Prompt the user for two hexadecimal integers. OR them together and display the result
Create a program that functions as a simple boolean calculator for 32-bit integers. It should display a menu that asks the user to make a selection from the following list:1. x AND y 2. x OR y 3. NOT x 4. x XOR y 5. Exit program When the user makes a choice, call a procedure that displays the name
Using the College Registration example from Section 6.7.3 as a starting point, do the following:• Recode the logic using CMP and conditional jump instructions (instead of the .IF and.ELSEIF directives).• Perform range checking on the credits value; it cannot be less than 1 or greater than 30.
Create a procedure named CalcGrade that receives an integer value between 0 and 100, and returns a single capital letter in the AL register. Preserve all other register values between calls to the procedure. The letter returned by the procedure should be according to the following ranges:Write a
Create a procedure that returns the sum of all array elements falling within the range j...k (inclusive).Write a test program that calls the procedure twice, passing a pointer to a signed doubleword array, the size of the array, and the values of j and k. Return the sum in the EAX register, and
Create a procedure that fills an array of doublewords with N random integers, making sure the values fall within the range j...k, inclusive. When calling the procedure, pass a pointer to the array that will hold the data, pass N, and pass the values of j and k. Preserve all register values between
10. Implement the following pseudocode in assembly language. Use short-circuit evaluation and assume that A, B, and N are 32-bit signed integers.while N > 0 if N != 3 AND (N < A OR N > B)N = N – 2 else N = N – 1 end whle
9. Implement the following pseudocode in assembly language. Use short-circuit evaluation and assume that X is a 32-bit variable.if( ebx > ecx AND ebx > edx) OR ( edx > eax )X = 1 else X = 2
8. Implement the following pseudocode in assembly language. Use short-circuit evaluation and assume that X is a 32-bit variable.if( ebx > ecx ) OR ( ebx > val1 )X = 1 else X = 2
7. Implement the following pseudocode in assembly language. Use short-circuit evaluation and assume that val1 and X are 32-bit variables.if( val1 > ecx ) AND ( ecx > edx )X = 1 else X = 2;
6. Write instructions that first clear bits 0 and 1 in AL. Then, if the destination operand is equal to zero, the code should jump to label L3. Otherwise, it should jump to label L4.
5. Write instructions that jump to label L2 when the signed integer in AX is greater than the integer in CX.
4. Write instructions that jump to label L1 when the unsigned integer in DX is less than or equal to the integer in CX.
3. Given two bit-mapped sets named SetX and SetY, write a sequence of instructions that generate a bit string in EAX that represents members in SetX that are not members of SetY.
2. Write instructions that calculate the parity of a 32-bit memory operand. Hint: Use the formula presented earlier in this section: B0 XOR B1 XOR B2 XOR B3.
1. Write a single instruction that converts an ASCII digit in AL to its corresponding binary value. If AL already contains a binary value (00h to 09h), leave it unchanged.
19. What will be the value of RBX after the following instructions execute?mov rbx,0FFFFFFFFFFFFFFFFh and rbx,80808080h
18. What will be the value of RBX after the following instructions execute?mov rbx,0FFFFFFFFFFFFFFFFh and rbx,808080h
17. What will be the value of RBX after the following instructions execute?mov rbx,0FFFFFFFFFFFFFFFFh and rbx,80h
16. (True/False): The following code will jump to the label named Target.mov eax,-42 cmp eax,26 ja Target
15. (True/False): The following code will jump to the label named Target.mov eax,-30 cmp eax,-50 jg Target
14. What will be the final value in EDX after this code executes?mov edx,1 mov eax,7FFFh cmp eax,0FFFF8000h jl L2 mov edx,0 L2:
13. What will be the final value in EDX after this code executes?mov edx,1 mov eax,7FFFh cmp eax,8000h jb L1 mov edx,0 L1:
12. What will be the final value in EDX after this code executes?mov edx,1 mov eax,7FFFh cmp eax,8000h jl L1 mov edx,0 L1:
11. How are JA and JNBE affected by the Zero and Carry flags?
10. Which conditional jump instruction executes a branch based on the contents of ECX?
9. In the following instruction sequence, show the values of the Carry, Zero, and Sign flags where indicated:mov al,00001111b test al,00000010b ;a. CF= ZF= SF=mov al,00000110b cmp al,00000101b ;b. CF= ZF= SF=mov al,00000101b cmp al,00000111b ;c. CF= ZF= SF=
8. In the following instruction sequence, show the resulting value of AL where indicated, in hexadecimal:mov al,7Ah not al ; a.mov al,3Dh and al,74h ; b.mov al,9Bh or al,35h ; c.mov al,72h xor al,0DCh ; d.
7. In the following instruction sequence, show the resulting value of AL where indicated, in binary:mov al,01101111b and al,00101101b ; a.mov al,6Dh and al,4Ah ; b.mov al,00001111b or al,61h ; c.mov al,94h xor al,37h ; d.
6. What will be the value of RBX after the following instructions execute?mov rbx,0AFAF649Bh xor rbx,0FFFFFFFFh
5. What will be the value of EBX after the following instructions execute?mov ebx,0AFAF649Bh or ebx,3A219604h
Showing 500 - 600
of 1525
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Last
Step by Step Answers