Does it Jump?
Looping
Branching
Procedures
Commands
100

mov eax, 5
mov ebx, 5
cmp eax, ebx
jne label

no :(

100

If your counter is in ecx, which command allows you to iterate through a loop ecx number of times?

loop loop_label

100

Assume x is in eax and y is in ebx.

How do you implement if (x==y) in assembly?

cmp eax, ebx
jne exit_branch
; if statement body
exit_branch:

100

Where is the return address stored during a procedure call?

The stack

100

What does the command jecxz do?

jumps if the ecx register contains 0

200

mov eax, 10
mov ebx, 15
cmp eax, ebx
jbe label

yes :)

200
Write the following for loop in assembly:

for (int i=5; i > 0; i--)
{body}

mov ecx, 5
loop_label:
   ; body
   loop loop_label

200

Assuming balance is in eax, write the following in assembly:
if (balance>=0)
{ do A}
else
{ do B}

cmp eax, 0
jnge do_else
; do A
jmp end_if
do_else:
; do B
end_if:

200

What 2 things happen when you make a procedure call?

1. The return address is pushed on to the stack

2. The program jumps to the start of the procedure

200

What is the difference between lea source and mov source?

lea loads the address of the source while mov loads the value of the source

300

mov eax, 7  
mov ebx, 10  
cmp eax, ebx  
jge label

no :(

300

Assuming x is in eax, write the following loop in assembly:
while (x< 10)
{body}

while_loop:
   cmp eax, 10
   jnl exit_loop
   ; body
exit_loop:

300

Assume x is in eax, y is in ebx, and z is in ecx.

How do you write if (x>y || z==0) in assembly?

cmp eax, ebx
jng exit_branch
cmp ecx, 0
jne exit_branch
; if statement body

300

What is a return address?

The address/location of instruction after a call

300

What does the command cmp eax, [ebx] do?

Compares the value in eax to the value at the address in ebx

400

mov eax, 0x00
mov ebx, 0x00
jnz label

no, cmp subtracts ebx from eax and sets the flags based on the difference. The difference is 0, so the zero flag is set. "Jump if not zero" is false.

400

Assuming x is in eax and y is in ebx, write the following in assembly:
while (x>100 && y<5)
{body}

while_loop:
   cmp eax, 100
   jng exit_loop
   cmp ebx, 5
   jnl exit_loop
   ; body
exit_loop:

400

What does the following assembly code evaluate?
cmp eax, ebx
jg body
cmp ecx, 0
je body
jmp endIf

body:
; do something
jmp endIf

endIf:

if eax > ebx or ecx==0

400

In assembly, what do the following commands do:
push ebp
mov ebp, esp

Stores the location of the old stack pointer and moves it to the current location of ESP (establishes the "bottom" of the stack for a procedure)

400

Which instruction can be added to movsb to move multiple bytes?

the REP command repeats a statement until ecx equals 0

500

mov eax, -1
mov ebx, 0
cmp eax, ebx
jns label

no, cmp subtracts ebx from eax and sets the flags based on the difference. The difference is -1, so the sign flag is set. "Jump if not signed" is false.

500
Assuming x is in eax, write the following loop in assembly:
while (x==False)
{body}

while_loop:
   cmp eax, 0
   jne exit_loop
   ; body
exit_loop:

500

What does the following assembly code evaluate?
cmp eax, ebx
jg greater
je equal
jmp less

greater:
; do A
jmp end

equal:
; do B
jmp end

less:
; do C

end:

if eax>ebx: do A
else if eax==ebx: do B
else: do C

500

Once a procedure has been called, we can access the first argument with [ebp+8]. What does this mean?

8 bytes above the base pointer on the stack

500

What's the difference between sar and shr?

sar is an arithmetic shift (extends the sign bit) and shr is a logical shift (pads with 0s)