Chapter 3 - Assembly Flashcards
Special Purpose Registers
IP SP Flags CS DS ES FS GS
IP
instruction pointer; points to next sequential instruction
SP
stack pointer; addresses stack area
flags
collection of control properties
12 bits
C flag
carry flag; holds the carry after addition or borrow after subtraction
Z flag
zero flag; reports the result of an arithmetic operation as zero
S flag
sign flag; holds the sign of the result after an arithmetic or logic instruction
O flag
overflow flag; indicates overflow as a result from signed arithmetic operations
CS
code segment; holds the programs used by the system
DS
data segment; contains most of the data used by program
data accessed by offset address
ES
extra segment; an additional data segment
SS
stack segment; defines the are of memory used for the stack.
Stack pointer register determines entry point in stack segment
FS & GS
additional segment registers
Real mode
allows the microprocessor to only address the 1st MB of memory. any program can access any area of memory
offset address
used to select a location within a 64kb segment to address a given program
Assembler start of program
.Model small
.stack 100h
Main PROC
mov ax, @data
mov ds, ax
Register Addressing
transfers a copy of a byte or word from one register to another
ex: mov ax, bx
Immediate addressing
transfers the source immediate byte (actual value) into a register or memory location
ex: mov ah, 0
Direct addressing
moves a byte or word between memory and AL, AX, or EAX registers ONLY
most operands must be the same size
ex: count DW 100H
temp DB 20
mov ax, count (or mov count, ax)
mov al, temp (or vice versa)
Displacement addressing
almost identical to direct addressing except instruction is 4 bytes wide instead of 3 bytes wide
How to move 8 bits into 16 bit register
2 moves
mov al, temp
mov ah, 00h
MOV operations allowed
all moves require the source and destination to be of the same size
memory to register; yes (and vice versa) x bit register to x bit register; yes x bit register to y bit register; no if x != y literal to memory; yes memory to memory; no
_GetCh
grabs char from input. result in BL register
_GetDate
grabs date.
DL = day DH = month CX = year AL = day of week
Binary subtraction for A - B
= A + twos_complement(B)
Twos Complement
flip the bits and add 1
Size of number as a result of multiplication
8 bit * 8 bit = 16 bit
16 bit * 16 bit = 32 bit
Multiplication operations
MUL; unsigned number multiplication
IMUL; signed number multiplication
Multiplication operation structure
register/memory location * al/ax
ex: C = A * B
A DW 10
B DW 5
C DW ?
mov ax, B mul A (or IMUL A)
if C <= 16 bits answer in AX
else
AX = lower 16 bits
DX = remaining upper bits
CBW
convert byte to word
sign extend a bye into a word
CWD
convert word to double
sign extend word to double word
Size of number as a result of division
16 bits / 8 bits = 8 bits
32 bits / 16 bits = 16 bits
Division Operations
DIV; unsigned number division
IDIV; signed number division
Division Operation Structure
register or eax or ax / reg or mem location
ex: Q = B/C
Q DW ?
R DW ?
B DW 12
C DW 4
mov Ax, B CWD (make AX into EAX) DIV C (or IDIV)
AX = quotient DX = remainder
Jump types
JE --> jump equals JNE --> jump not equals JL --> jump less than JG --> jump greater than JGE --> jump greater than or equal JNGE --> jump not greater than or equal JLE --> jump less than or equal JNLE --> jump not less than or equal JMP --> unconditional jump
What happens when jump instruction is called?
if the criteria is true, then the program jumps to the specified label
What does CALL do?
pushes IP on to stack
replaces current address of IP with address of subprogram
What does RET do?
pops the return address from the stack into IP plus the number of bytes specified
What happens to begin each subprogram?
save the current bp, set sp equal to bp
How to add subprogram parameters?
Parameters pushed on stack from left to right. First parameter located at word ptr [bp + 4], the second at word ptr [bp + 6] etc. (the IP at [bp+2]
Where are local variables in the stack frame?
at word ptr [bp-2], word ptr [bp -4] etc.