x86 assembly language Flashcards

1
Q

How can you preserve the values of function registers across function calls.

A

pushing to stack then poping after function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How does using a callee saved register work?

A

The value needs to be preserved when the function returns. push at the beginning of the function and pop at the end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does the following command do?
movq $0x501208,%rdi

A

puts the constant 0x501208 into rdi

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the following command do?
movq %rax,%rdi

A

moves contents of register rax to rdi

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does the following command do?
movq %rsi,(%rdi)

A

Stores the value in rsi in the address contained in rdi

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the following command do?
movq 0x501208,%rdi

A

Fetches contents in address 0x501208 and stores it in rdi

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the commands at the start of every function to save the frame pointer in x86?

A

pushq %rbp
movq %rsp, %rbp

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the instructions at the end of a function in x86?

A

leave
ret

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you assemble and run a program named t1.s?

A

gcc -static –g -o t1 t1.s
./t1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does cmpq S2, S1 do?

A

S1-S2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does testq S2, S1 do?

A

S1 & S2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are some conditional jump instructions?

A

JE (jump equal)
JNE (jump not equal)
JGE (Jump if greater or equal)
JNGE (Jump if not greater or equal)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you run the below program? The function is in an assembly file?

maxarray.c:
#include <stdio.h></stdio.h>

long a[] = {4, 6, 3, 7, 9, 5 };
long maxarray(long n, long *a);
int
main()
{
printf(“maxarray(6,a)=%ld\n”, maxarray(6,a));
}

A

gcc -g -static -o maxarray maxarray.c maxarray.s

./maxarray

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you declare a global variable in assembly for a long named a?

A

.data
.comm a,8 # long a;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you move the immediate value of a global array into a register? (double check correct)

A

Using dollar sign before $

ex: movq $a, %rsi

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the size of “regular” registers in x86 assembly?

A

8 bytes

17
Q

How do we do single byte manipulation in assembly?

A

Use byte registers like %r13b

Also use movb instead of movq

18
Q

What is the stack used for?

A

● store the return address
● store local variables
● Save registers when running out of them (register
spill).
● pass arguments when they don’t fit in the
registers.

19
Q

Think of an example of using the stack in an assembly program

A

.globl sum

.type sum, @function

sum:

#

pushq %rbp # Save frame pointer
movq %rsp, %rbp #
subq $24, %rsp # Create space in stack for
# tmp1, tmp2 and result

movq %rdi, -8(%rbp) # tmp1 = a
movq %rsi, -16(%rbp) # tmp2 = b
movq -8(%rbp), %rax
addq -16(%rbp), %rax
movq %rax, -24(%rbp) # result = tmp1 + tmp2 ;
movq -24(%rbp), %rax # return result ;
leave # eq. mov %rbp,%rsp
# pop %rbp

ret