CSC 521-001: Advanced Computer Architecture Spring 2025
Midterm - Assembly Grade: /50
For this part of the exam YOU MAY NOT:
• use any outside resources besides notes/programs generated within the class.
• discuss with a peer within or outside the class in any way.
• use any social media apps or messaging platforms (WhatsApp, Discord, etc...).
• use any LLMS or AI to write your code (or in any other way).
• use a device other than your computer.
• share your code with a peer in any way.
If for any reason you break any of these rules you will fail both parts of the exam.
For the following make sure to use techniques taught in class. Also, make sure to
submit all only your .asm files only.
1. (15 pts) Convert the provided Python code to x86-64 Assembly using NASM
(called one.asm):
from sys import argv
def calculateLetter ( grade ) :
if ( grade >= 90) :
return " A "
elif ( grade >= 80) :
return " B "
elif ( grade >= 70) :
return " C "
elif ( grade >= 60) :
return " D "
else :
return " F "
print ( calculateLetter ( int ( argv [1]) ) ) # prints -> D
print ( calculateLetter ( int ( argv [2]) ) ) # prints -> A
print ( calculateLetter ( int ( argv [3]) ) ) # prints -> C
# bash run . sh one 60 92 72
1
2. (15 pts) Convert the provided Python code to x86-64 Assembly using NASM
(called two.asm):
# make sure to not hardcode the offsets
# handle the values in the array dynamically
numbers = [50 , 65 , 2555 , -588 , 0 , 950]
def update ( array ) :
for i in range ( len ( array ) ) :
array [ i ] += array [ i ]
return array
numbers = update ( numbers )
for number in numbers :
print ( number ) # 100 , 130 , 5110 , -1176 , 0 , 1900
3. (10 pts) Write an assembly program (called three.asm) that swaps the values
of two 32-bit integers stored in memory, using only the stack and registers. Do
not use a direct MOV such as MOV [a], [b].
• Use only the RAX register.
– Hint: You may need to use the push/pop idea when trying to print.
• Make sure to “print ret” after every step.
; Example Output
1234
5678
5678
1234
2
4. (10 pts) Write an assembly program (called four.asm) that counts down from
15 to 0, printing all values multiplied by 4.
• Use only the RAX register.
– Hint: You may need to use the push/pop idea when trying to print.
• Do not use MUL/IMUL instructions
• Make sure to “print ret” after every iteration.
; Example Output
60
56
52
48
44
40
36
32
28
24
20
16
12
8
4
0