sample midterm2

docx

School

De Anza College *

*We aren’t endorsed by this school

Course

D21JA

Subject

Computer Science

Date

Dec 6, 2023

Type

docx

Pages

3

Uploaded by notorioushrc

Report
CIS 21JA - Midterm 2 sample 1) (11 Pts) Given the following program: 1) Show all values in the stack until line A runs. 2) Show the output of this code. arr byte 'a','b','a' .code main proc sub esp, 4 push lengthof arr Push offset arr call p1 Pop eax Call writeDec exit main endp p1 proc Push ebp Mov ebp, esp Push ebx Push ecx Push eax push edx mov ebx, [ebp + 8] mov ecx, [ebp + 12] Xor eax, eax mov [ebp + 16], eax lea edx, [ebp + 16] ; edx = ebp + 16 L1: Push [ebx] push edx Call p2 inc ebx Loop L1 pop edx Pop eax Pop ecx Pop ebx Pop ebp Ret 8 P1 endp P2 proc Push ebp Mov ebp, esp Push eax push esi Mov eax, [ebp + 12] Cmp al, 'a' Jne L1 mov esi, [ebp + 8] inc dword ptr [esi] ;Line A L1: pop esi Pop eax Pop ebp Ret 8 p2 endp end main esp Address increases
(2) You are given the following data segment: .data num1 qword 123456789abcdeffh ; 12 34 56 78 9A BC DE FF num2 qword 0000000070000000h ; 00 00 00 00 70 00 00 00 result qword ? ; 12 34 56 79 0A BC DE FF ;result after your program ends In C++, the header of a function to add the two arguments could be void addQword (int &num1, int &num2, int &result) ; result, num1, num2 reference unsigned qwords Pay attention that the symbol “&” means that you are passing by reference a)(4 pts) Show assembly language code appropriate for “main” that: 1. calls the proc addQword. 2. prints out the value of result to the output screen; use writeHex You can’t pass by registers or global variables. You must use the stack. b)( 11 pts) Starting with the PROC directive and ending with the ENDP directive, write addQword proc. Follow 32 bit stdcall protocol where the callee cleans the stack . Preserve any registers that you use in the stack.
3)(6 pts) Implement the following design. Assume you are dealing with DWORD signed integers and calculations won’t exceed 4 bytes at any time. if ((eax >= 10 ) or (eax < 2) ) Total+ = eax else Total -= eax 4) (18pts) Each of these problems gives “before” conditions and an instruction. Give the indicated “after” state in hex . Before Instruction Executed After a) EAX: FF FF 8E BA test ax, 71h SF: ZF: EAX: b) EAX: 00 00 00 04 imul bx EAX: EBX: FF FF FF FD EDX: EDX: 45 CF FF FE c) ESP: 00 63 FB 60 Ret 12 ESP: d) EAX: FF FF FF F2 cdq EAX: EBX: 00 00 00 03 idiv ebx EDX: EDX: FD 00 10 20 e) EAX: FF FF 8E BA or al, 09h SF: ZF: EAX:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help