Uploaded by Minh Châu Đoàn

Copy-of-Topic05-Assembly

advertisement
Working with Assembly
Forming Group
Start time:9:05
In this activity, you work in teams of 2~3 students to learn new programming concepts.
Content Learning Objectives
1. Understand Assembly code
2. Understand
3. Understand how bubble affect performance
Role
Project Manager: reads the questions aloud, keeps track of time and
makes sure everyone contributes appropriately.
Name
Hung Nguyen
1. Clicks on FILE-> MAKE A COPY
2. Shares the copy with all the other team members using their
UMass email address
Recorder: records all answers in the Google doc shared by the
Manager and ensures the team agrees on responses.
Hacker: execute the code.
Hung Nguyen
Please assign the page number for each question, otherwise,
you will receive 0.1 deduction for each question.
(50 min) Activity 1. Interpret Assembly Code
Start time:
It’s your time to practice how to execute this assembly code in an intel x86 32-bit machine. In
this exercise, you will need to run each line of assembly and update the table given in each
question.
Here is the Assembly Cheat Sheet
Q1. Basic Assembly
Register
Initial value
eax
3
ecx
8
edx
1
ebx
15
Register
final value
eax
6
ecx
7
edx
1
ebx
1
<Code>
MOVL $6, %eax
MOVL %eax, %ecx
MOVL %edx, 6(%ebx)
ADDL 6(%ebx), %ecx
IMULL %eax, 6(%ebx)
ANDL %edx, %ebx
Answer:
Q2. Push and Pop. Drawing a stack might be helpful for this question.
Register
Initial value
eax
3
ecx
8
ebx
1
ebp
32
esp
16
Register
final value
eax
8
ecx
3
ebx
8
ebp
16
esp
12
<Code>
MOVL %esp, %ebp
PUSHL %eax
PUSHL %ecx
MOVL (%esp), %eax
MOVL 4(%esp), %ecx
POPL %ebx
Answer:
Q3. Conditional
Register
Initial value
eax
7
ecx
8
edx
1
ebx
15
Register
final value
eax
16
ecx
17
edx
7
ebx
9
<Code>
MOVL %eax, 8(%ebx)
ADD %ecx, 8(%ebx)
CMPL 8(%ebx), %eax
JLE .L2
JMP .L5
.L2:
MOVL $7, %edx
CMPL %ebx, 8(%ebx)
JNE .L3
JMP .L4
.L3:
MOVL $23, %eax
MOVL $24, %ecx
.L4:
MOVL $16, %eax
MOVL $17, %ecx
.L5:
MOVL $9, %ebx
Answer:
Q4. Loop
Register
Initial value
eax
3
ecx
8
edx
1
ebx
15
Register
final value
eax
9
ecx
8
edx
22
ebx
7
<Code>
MOVL %ecx, 8(%ebx)
.L1:
CMPL 8(%ebx), %eax
JLE .L2
JMP .L4
.L2:
ADD $5, %edx
CMPL %edx, %ebx
JLE .L3
ADD $6, %edx
.L3:
ADD $2, %eax
JMP . L1
.L4:
MOVL $7, %ebx
Answer:
Q5. Array
We create an int array in a program as follows. If we know -32(%ebp) is the memory address of the
start of this array, what are the array values after running the code below? Drawing a stack might be
helpful for this question.
20
19
35
7
19
35
4
<Code>
MOVL $4, eax
MOVL $8, ebx
MOVL $100, -32(%ebp)
MOVL %eax, -20(%ebp)
MOVL %ebx, -12(%ebp)
Answer:
100
Good job! You have worked with Assembly
Create a pdf of this worksheet file and upload it in Gradescope.
Please assign the page number for each question, otherwise,
you will receive 0.1 deduction for each question.
Download