Computer Science homework help
Computer Science homework help. Name: ______________________
CSC 220 – Exam 2
Part I (24 Points):
- Define the data structure Stacks.
- Which instructions pushes and pops all of your 32-bit general purpose registers onto the stack?
- What are alternative instructions involving stacks to save and load our status flags (SAHF and LAHF)?
- Define the ESP register and describe what happens to the address of the ESP when pushing and popping values on the stack.
- When pushing register values onto the stack and then popping them back into the appropriate registers. In what the order is the values are returned? Why?
- Describe the CALL and RET instructions and how the runtime stack is involved.
Part II (36 Points):
- Write an instruction that clears bit 0, 2, 5, 7 in register AL.
- Write an instruction that checks if bits 3, 4, 5, 6 are set in register AL.
- Write an instruction that clears the zero flag when bit 5 is set and sets the zero flag when bit 5 is not set in register AL WITHOUT altering the values within AL.
- Given SetX, SetY, and SetZ. Find the union of SetX and SetY that intersects SetZ.
- Write a sequence of push and pop instructions to swap the values of EAX and EBX.
- Trace this program and describe what happens and why.
main PROC
mov EAX, 0
mov EDX, 10000h
push EDX
call mySubroutine
main ENDP
mySubroutine PROC
PUSHAD
PUSH 20000h
POP EBX
POP ECX
POPAD
RET
mySubroutine ENDP
Part III (40 Points):
- Create a Procedure that returns the original value of EBX and EDX after the procedure ends. Increment EBX and decrement EDX. Afterwards, it will swap the values of EBX and EDX then it will perform EAX = EAX + EBX each time the procedure is called.
After creating your procedure, initialize EAX as 0, EBX as 20, EDX as 25. Create a loop that loops 5 times calling your procedure.
- Create a procedure that sums up the given array and in the main procedure call the procedure you created then move the sum into EAX.
.data
array DWORD 10000000h, 2000000h, 300000h, 40000h
.code
- Translate the following code to Assembly:
(signed)
-
- if ( A < B ) {
C = A ;
B = B – 10 ;
}
else {
C = B ;
A = A + 10 ;
}
(unsigned)
-
- if ( (EAX == EBX) && (ECX > EDX) ) {
EAX ++ ;
- if ( (EAX == EBX) && (ECX > EDX) ) {
EAX = ECX;
}
else if ( (EAX < EBX) || (ECX < EDX) ) {
EBX ++ ;
EBX += EAX ;
}
else {
EBX ++ ;
EBX = EAX ;
}