x86 assembly language Flashcards
How can you preserve the values of function registers across function calls.
pushing to stack then poping after function
How does using a callee saved register work?
The value needs to be preserved when the function returns. push at the beginning of the function and pop at the end
What does the following command do?
movq $0x501208,%rdi
puts the constant 0x501208 into rdi
What does the following command do?
movq %rax,%rdi
moves contents of register rax to rdi
What does the following command do?
movq %rsi,(%rdi)
Stores the value in rsi in the address contained in rdi
What does the following command do?
movq 0x501208,%rdi
Fetches contents in address 0x501208 and stores it in rdi
What are the commands at the start of every function to save the frame pointer in x86?
pushq %rbp
movq %rsp, %rbp
What are the instructions at the end of a function in x86?
leave
ret
How do you assemble and run a program named t1.s?
gcc -static –g -o t1 t1.s
./t1
What does cmpq S2, S1 do?
S1-S2
What does testq S2, S1 do?
S1 & S2
What are some conditional jump instructions?
JE (jump equal)
JNE (jump not equal)
JGE (Jump if greater or equal)
JNGE (Jump if not greater or equal)
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));
}
gcc -g -static -o maxarray maxarray.c maxarray.s
./maxarray
How do you declare a global variable in assembly for a long named a?
.data
.comm a,8 # long a;
How do you move the immediate value of a global array into a register? (double check correct)
Using dollar sign before $
ex: movq $a, %rsi