You, as an individual, are expected to do your own work. This means you cannot seek, receive or otherwise acquire any assistance except clarifications from the professor during an examination. Any communication involving the contents of the subject matter or the examination is considered cheating. Do not initiate or accept such communication, or the result of your examination is automatically voided.
Each correct answer is worth one point, each wrong answer is worth zero point, and each unanswered question is also worth zero point. This means you should guess and leave no question unanswered.
Make sure you write down you name on the upper right corner first, otherwise I cannot give points to anonymous students!
.data a: .long 0x3, 0x6, 0x31, 0x0, 0x5, 0x7, 0x3, 0x6 n = (. - a) / 4 .text .global _start _start: movl %esp,%ebx movl $a, %eax L1: pushl (%eax) cmpl $0,(%eax) jz L2 addl $4,%eax jmp L1 L2: call sub1 movl %ebx,%espWhen subroutine
sub1 gets control, how many bytes are pushed
on the stack by the caller, not counting the return address?
sub1. Assuming sub1 is called from the code in
1, what is the value of eax right before
the ret instruction?
sub1: pushl %ebp movl %esp,%ebp pushl %ebx movl %ebp,%ebx addl $8,%ebx movl $0,%eax L3: cmpl $0,(%ebx) jz L4 addl (%ebx),%eax addl $4,%ebx jmp L3 L4: popl %ebx popl %ebp ret
0x3+0x6+0x31
0x3+0x6+0x31+0x0+0x5=0x7+0x3+0x6
.text .global _start _start: pushl $L1 jmp sub1 L1: nop movl $1,%eax movl $0,%ebx int $0x80 sub1: ret
pushl $L1 is not a valid instruction
ret instruction
nop
instruction
int $0x80
movl %esp, %ebp
pushl $0
popl %eax
call sub1
ret
.data str: .asciz "abcde" .text .global _start _start: movl $str,%eax movl %esp,%ebp sub1: cmpb $0,(%eax) jz L1 pushl %eax addl $1,%eax call sub1 popl %ecx movl $4,%eax movl $1,%ebx movl $1,%edx int $0x80 L1: cmpl %esp,%ebp jz L3 ret L3: movl $1,%eax movl $0,%ebx int $0x80
abcde, completes without any crash
edcba
a
e
abcde, then crashes
eax and ebx immediately
after the following instructions? Assume the stack is set up
correctly before these four instructions, and it has at least
eight bytes remaining.
movl $12,%eax
movl $678,%ebx
pushl %eax
pushl %ebx
popl %eax
popl %ebx
eax has 12, and ebx has 678
eax has 12, and ebx has 12
eax has 678 and ebx has 12
.data str: .asciz "This is a string." .text .global _start _start: pushl $str call sub1 addl $4,%esp
In the subroutine sub1, how do we load the first character
of the string at str into register bl? Assume
all registers are at your disposal, and the
beginning of sub1 is as follows:
sub1: pushl %ebp movl %esp,%bp
movb 4(%ebp),%bl
movb 8(%ebp),%bl
movl 8(%ebp),%eax
movb (%eax),%bl
movl 4(%ebp),%eax
movb (%eax),%bl
movl %ebp,%eax
movb 4(%eax),%bl
ax after the following instructions?
pushl $0x12345678 popw %ax
0x1234
0x12
0x5678
0x78
0x34