1. Assume that you are given values in eax, ebx, ecx. Write an assembly code that does the following: eax = (ecx + edx ) - (eax + ebx)
2. Write a piece of code that copies the number inside al to ch. Example: Assume that Initially eax = 0x15DBCB19. At the end of your code ecx = 0x00001900. Your code must be as efficient as possible.
3. You are given eax = 0x5. Write one line of code in assembly to Zero eax. Don't use Sub instruction and mov instruction. You must use hex numbers only as immediate numbers.
4. Implement the following arithmetic expression in assembly language: EBX = var1 - var2 - 9 + var3 // size of variables, 4 bytes each
5. Write a piece of code in assembly that implements the following C++ statement num1 = num2 = 4; // x and y are of size word (2 bytes)
6. Write a piece of code that implements the following C++ statements d = 'w'; // a ,d,b are of size byte. a = d + 1; b = a + 2;
Part two:(8 points) Open hello.asm. Before the exit line of code, add the line of code: mov ebx, -20 add ebx, 1 Save and build the project. Set a breakpoint after the add line that you just added. Run to the break point Open the debug window to see all the registers. Select Step Into (F11) to run the add line of code Show what values are in the following registers: BL: BH: BX: EBX
Question 1:Assume that you are given values in eax, ebx, ecx. Write an assembly code that does the following: eax = (ecx + edx ) - (eax + ebx)
Solution: This assembly code is an iterpretation of its c counterpart.
************************************************************************************
.LC0:
.string "%d %d %d %d"
.LC1:
.string "%d"
main:
push rbp
mov rbp, rsp
sub rsp, 16
lea rsi, [rbp-16]
lea rcx, [rbp-12]
lea rdx, [rbp-8]
lea rax, [rbp-4]
mov r8, rsi
mov rsi, rax
mov edi, OFFSET FLAT:.LC0
mov eax, 0
call scanf
mov edx, DWORD PTR [rbp-12]
mov eax, DWORD PTR [rbp-16]
lea ecx, [rdx+rax]
mov edx, DWORD PTR [rbp-4]
mov eax, DWORD PTR [rbp-8]
add eax, edx
sub ecx, eax
mov eax, ecx
mov DWORD PTR [rbp-4], eax
mov eax, DWORD PTR [rbp-4]
mov esi, eax
mov edi, OFFSET FLAT:.LC1
mov eax, 0
call printf
mov eax, 0
leave
ret
*******************************************
Question 2:Write a piece of code that copies the number inside al to ch. Example: Assume that Initially eax = 0x15DBCB19. At the end of your code ecx = 0x00001900. Your code must be as efficient as possible
Solution:
************************************
.LC0:
.string "%d"
.LC1:
.string "%d %d"
main:
push rbp
mov rbp, rsp
sub rsp, 16
lea rax, [rbp-4]
mov rsi, rax
mov edi, OFFSET FLAT:.LC0
mov eax, 0
call scanf
mov eax, DWORD PTR [rbp-4]
mov DWORD PTR [rbp-8], eax
lea rdx, [rbp-8]
lea rax, [rbp-4]
mov rsi, rax
mov edi, OFFSET FLAT:.LC1
mov eax, 0
call printf
mov eax, 0
leave
ret
*************************************
Question 4:Implement the following arithmetic expression in assembly language: EBX = var1 - var2 - 9 + var3 // size of variables, 4 bytes each
Solution:
**********************************
main:
push rbp
mov rbp, rsp
mov eax, DWORD PTR [rbp-4]
sub eax, DWORD PTR [rbp-8]
lea edx, [rax-9]
mov eax, DWORD PTR [rbp-12]
add eax, edx
mov DWORD PTR [rbp-16], eax
mov eax, 0
pop rbp
ret
************************************
Question 6:Write a piece of code that implements the following C++ statements d = 'w'; // a ,d,b are of size byte. a = d + 1; b = a + 2;
Solution:
***************************
main:
push rbp
mov rbp, rsp
mov BYTE PTR [rbp-1], 119
movzx eax, BYTE PTR [rbp-1]
add eax, 1
mov BYTE PTR [rbp-2], al
movzx eax, BYTE PTR [rbp-2]
add eax, 2
mov BYTE PTR [rbp-3], al
mov eax, 0
pop rbp
ret
*************************************
1. Assume that you are given values in eax, ebx, ecx. Write an assembly code that...
Assembly Memory Segment Layout (Little Endian) - What does the "add" instruction do?For example, on the first add instruction (add eax, 3), it moves the pointer for eax 3 spots to the right.Thus, EAX = 12, 17, A3, 00. (This I understand)But, on the second add instruction (add ebx, 5), it actually adds the value 5 to ebx, making EBX = 12, 17, A3, 05.Why is that?ANSWER:varl var2 var3 dd 179 db 0A3h, 017h 012h bca var1 eax. mov add...
Question#1 Write a short program demonstrating that the INC and DEC instructions do not affect the Carry flag. Question#2 Write a program that uses addition and subtraction to set and clear the Overflow flag. After each addition or subtraction, insert the call DumpRegs statement to display the registers and flags. Make sure to include an ADD instruction that sets both the Carry and Overflow flags. Using comments, explain how and why the Overflow flag was affected by each instruction. Question#3...
I need help creating this code. Write an assembly program (MASM and Irvine's libraries) that calculates and prints out the first five Fibonacci numbers FO=0; F1=1; F2=1; F3=F1+F2; F4=F3+F2; F5=F4+F3 If we use 0, 1 and initial conditions the sequence would be: 0, 1, 1, 2, 3 Use the ebx, eax, and ecx registers. Note WriteHex, Writelnt, WriteDec, all use eax So use ebx for first and eax for second and ecx for temporary The calculation could go something like...
X86 Assembly Language Help to implement the CipherChar Procedure at the end of the given code INCLUDE Irvine32.inc .data KeyPrompt BYTE "Enter the passphrase: ",0 TextPrompt BYTE "Enter the plaintest: ",0 str1 BYTE "The passphrase has length:",0 str2 BYTE "The plaintest has length:",0 KeyIs BYTE "The passphrase: ",0 PlainTextIs BYTE "The plaintext: ",0 CipherTextIs BYTE "The ciphertext: ",0 KMAX = 64 ; passphrase buffer maximum size BMAX = 128 ; test...
Assembly language: Before executing the following code, the value in eax was 1 What will be the value in eax after executing the following code: mov ebx, eax shl eax, 4 shl ebx, 3 add eax, ebx
Assembly language. You can see the question in blue box. Loop Instruction Problem 4: Write and run a program and answer the questions in the box. .data temp dword? First, build and run the program .code - Trace ECX value mov eax,0 ECX=? mov ecx, 10 ; outer loop counter - EAX =? L1: Second: If we removed mov ecx, temp mov eax, 3 What will happen? mov temp.ecx mov ecx,5 ; inner loop counter - build and run the...
1) Assume the registers are initialized to the indicated values: Se al A c and code frogments MUST use 32 ぁ ar movennes (anor be "nedfra-ne ibrary function or procedural calls ino- Pe Peue c for ll codr ond code frogments only othu ey document your code with Comments unless the code size is Drow Fow Chort for any flow of control involving branches and loops Use PoCedures as modules to organize most of the code and code fragments. In...
NOTE: explain the lines in comments for better understanding Write an assembly program (for x86 processors - Irvine) that has two procedures, a main procedure and a procedure called Fib. The fib procedure is to uses a loop to calculate and printout the first N Fibonacci numbers. Fibonacci sequence is described by the following formula: Fib(1) = 1, Fib(2) = 1, Fib(n) = Fib(n – 1) + Fib(n – 2). The value of N is to be communicated to this...
Understanding assembly language: The assembly language for cars() is: (gdb) disass cars Dump of assembler code for function vanilla: 0x00000000004004cd <+0>: push %rbp 0x00000000004004ce <+1>: mov %rsp,%rbp 0x00000000004004d1 <+4>: mov %edi,-0x14(%rbp) 0x00000000004004d4 <+7>: mov -0x14(%rbp),%eax 0x00000000004004d7 <+10>: add %eax,%eax 0x00000000004004d9 <+12>: mov %eax,-0x4(%rbp) 0x00000000004004dc <+15>: mov -0x4(%rbp),%eax 0x00000000004004df <+18>: mov -0x14(%rbp),%edx 0x00000000004004e2 <+21>: add %edx,%eax 0x00000000004004e4 <+23>: pop %rbp 0x00000000004004e5 <+24>: retq End of assembler dump. Give a 1-2...
assembly language LAB #11-IMPLEMENT SLIDE #56 of the CHAPTER SEVEN SLIDES IN TWO WAYS EBX contains 200; ECX contains 42 1) Using SHIFT INSTRUCTIONS 2) Using the MUL and DIV INSTRUCTIONS Implement the following expression using signed 32-bit integers: eax = (ebx * 20) / ecx mov eax,20 imul ebx idiv ecx LAB #11-IMPLEMENT SLIDE #56 of the CHAPTER SEVEN SLIDES IN TWO WAYS EBX contains 200; ECX contains 42 1) Using SHIFT INSTRUCTIONS 2) Using the MUL and DIV...