Computer Science homework help

Computer Science homework help. Name: ______________________
CSC 220 – Exam 2
 
Part I (24 Points):

  1. Define the data structure Stacks.

 

  1. Which instructions pushes and pops all of your 32-bit general purpose registers onto the stack?

 

  1. What are alternative instructions involving stacks to save and load our status flags (SAHF and LAHF)?

 

  1. Define the ESP register and describe what happens to the address of the ESP when pushing and popping values on the stack.

 

  1. 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?

 

  1. Describe the CALL and RET instructions and how the runtime stack is involved.

 
Part II (36 Points):

  1. Write an instruction that clears bit 0, 2, 5, 7 in register AL.

 

  1. Write an instruction that checks if bits 3, 4, 5, 6 are set in register AL.

 

  1. 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.

 

  1. Given SetX, SetY, and SetZ. Find the union of SetX and SetY that intersects SetZ.

 

  1. Write a sequence of push and pop instructions to swap the values of EAX and EBX.

 

  1. 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):

  1. 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.
 

  1. 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
 

  1. Translate the following code to Assembly:

(signed)

    1. if ( A < B ) {

C = A ;
B = B – 10 ;
}
else {
C = B ;
A = A + 10 ;
}
 
 
 
 
 
 
 
 
(unsigned)

    1. if ( (EAX == EBX) && (ECX > EDX) ) {
      EAX ++ ;

EAX = ECX;
}
else if ( (EAX < EBX) || (ECX < EDX) ) {
EBX ++ ;
EBX += EAX ;
}
else {
EBX ++ ;
EBX = EAX ;
}

Computer Science homework help