In: Computer Science
Give an example of the pair of assembler instructions equivalent to a push using 32 bit ISA.
ISA: Stands for Instruction Set Architecture
It is the boundary between software and hardware.
3 most common types of ISAs are:
Stack (Push, Pop, Add) - The operands are implicitly on top of the
stack.
Accumulator (Load, Add, Store) - One operand is implicitly the
accumulator.
General Purpose Register (GPR)
Push stores a 64-bit register out onto the stack.
The 64-bit registers are those like "rax" or "r8"
32-bit registers like "eax" or "r8d".
If we use eax register with push it gives an error "instruction not supported in 64-bit mode. So we must use push rax 64 bit instead.
32 Bit Register are:
eax, edx, ecx, ebx, esp, ebp, esi, edi, r8d, r9d, r10d, r11d, r12d,
r13d, r14d, r15d
Set up Stack Segment with 16-bit stack push to SP and the stack
should be aligned as two byte as 16-bit register occupies one slot
and pushing a 32-bit register occupies two slots
16 bit register + 16 bit register into one slot of 32bit.
verify this to yourself with the following code:
push eax
pop ax
pop bx
Example; nasm -f bin -o test32.com test32.asm
bits 16
org 100h
mov eax, 11112222h
push eax
pop ax
pop dx
call ax2hex
mov ax, dx
call ax2hex
ret
ax2hex:
push cx
push dx
mov cx, 4
.top
rol ax, 4
mov dl, al
and dl, 0Fh
cmp dl, 9
jbe .dec_dig
add dl, 7
.dec_dig:
add dl, 30h
push ax
mov ah, 2
int 21h
pop ax
loop .top
pop dx
pop cx
ret