Assembly Part 2 Flashcards
.file
Allows a name to be assigned to assembly language source code file
.section
This makes the specified section the current section (required)
.rodata
Specifies that the following data to be placed in the read only memory portion of the executable (required if you have read only data)
.data
Changes or sets the current section to the data section
.text
Changes or sets the current section to the text (or code) section
.globl
A directive needed by linker for symbol resolution: followed by name of function
.type
Needed by the linker to identify the label associated with a function, as opposed to data
.size
Needed by the linker to identify the size of the text for the program
.align
Needed if we want to declare values on the head to start an address that has a particular byte alignment (1,2,4,8)
What happens if you want to declare static class variables
In the .data or .rodata section of program, you need to declare the values
.quad value
.long value
.word value
.byte value
.string
.quad
Places given value in memory encoded by 8 bytes
Other data sizes
.long, .,words, .byte, .string
Leaq
Address computation
Sale
Shift arithmetic left
Imulq
Signed multiply
The program stack is divided conceptually into ____
Frames
Each procedure or function has its own part of the stack to use which is called the ____
Stack frame
The stack frame goes from the stack address pointed to by ___. This is called the ___/____ pointer to %______ which points to the ____ of the stack
%rbp, frame,base, top
_____ must be set when the procedure is entered
%rbp
First use of stack
Save the _____ %rbp before setting our frame pointer
Caller
Second use of stack
Before calling another function, perverse values needed using ____/_____
Push, pop
Third use of stack
To pass _____ to another function (only if there are more than 6 parameters to pass)
Parameters
Fourth use of stack
To store the _______ ________ when a call instruction is executed
Return address
Fifth use of the stack
If we need more _______ _______ than available registers (automatic, block scope)
Temp data
PushX source
Decrement %rsp by number of bytes specified in oppose suffix and write bytes (of size specified by suffix) to memory address %rsp
We can push a value of a _____, a value from _____ to the stack, and a _____ to the stack
Register, memory, stack
_____ and _____ push instructions are NOT valid
Push, pushb
Only push and pop _____ byte value to stack
8
PopX destination
Reads number of bytes specified by suffix from the address %rsp and store in destination. Increment %rsp by number of bytes specified by oppose suffix so rsp points to next value on stack
First thing to do when setting up program stack
1. Set %rbp to point to _____ of current stack frame
Bottom
Setting up program stack
2. Set %rsp to current ____ of stack (same address as the stack bottom initially)
Top
At the end of function, what to do with rsp and rbp?
Put them back
CallX does two things
1. The _____ of the instruction immediately after the call instruction is pushed onto the stack (that is, the return address is pushed)
2. The _____ is assigned to the PC (%rip) register
Address, Dest
Setting up stack frame
- Push %rbp #save caller’s base pointer
- Movq %rsp, %rbp #set my base pointer
%rbp is equal to %rsp, the stack frame is empty and we are ready to use the stack
When leaving a function
Leave. # set caller’s stack frame back up
Leave is equivalent to
Movq %rbp, %rsp
Pop %rbp
RetX
1. The ____ of the instruction immediately after the ______ instruction that got us here is popped from the stack
2. The address is assigned to the PC (%rip) register
Address, call
1st step in setting up stack frames
Pushq %rbp —> save caller’s base pointer of the stack
2nd step in setting up stack frame
Move %rsp, %rbp -> set the base pointer
Now rsp equals rbp, this means the stack frame is empty and stack is ready to use
RetX does 2 things
1. The ____ of the instruction immediately after the call instruction that got us here is popped from the stack
2. That address is assigned to the ______ (___) register
Address, PC, %rip