mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-20 02:56:44 +00:00
add PUSHF
and POPF
documentation
parent
6cfefdcb2e
commit
64c0f7b1da
@ -917,8 +917,49 @@ destination = destination - 1
|
|||||||
```
|
```
|
||||||
|
|
||||||
### POPF
|
### POPF
|
||||||
|
#### Details
|
||||||
|
| mnemonic | opcode | operands | carry | zero | sign | overflow | break |
|
||||||
|
| -------- | ------ | -------- | ----- | ---- | ---- | -------- | ----- |
|
||||||
|
| `POPF` | `0x2C` | | `X` | `X` | `X` | `X` | `-` |
|
||||||
|
|
||||||
|
#### Description
|
||||||
|
Pops a word of the top of the stack and uses the 4 lowest bits of the result to set the CPU flags. In the order *sign*, *zero*, *carry* and *overflow* also represented by the following bit pattern `xxxx xxxx xxxx SZCO`.
|
||||||
|
|
||||||
|
All flags will be according to the corresponding bit values of given word. To only set on flag a `PUSHF` to query the flags and a bitmask with the desired flag to manipulate should be used.
|
||||||
|
|
||||||
|
#### Pseudo code
|
||||||
|
```py
|
||||||
|
flags = memory[SP]
|
||||||
|
|
||||||
|
SIGN_FLAG = flags & (1 << 3)
|
||||||
|
ZERO_FLAG = flags & (1 << 2)
|
||||||
|
CARRY_FLAG = flags & (1 << 1)
|
||||||
|
OVERFLOW_FLAG = flags & 1
|
||||||
|
|
||||||
|
SP = SP + 1
|
||||||
|
```
|
||||||
|
|
||||||
### PUSHF
|
### PUSHF
|
||||||
|
#### Details
|
||||||
|
| mnemonic | opcode | operands | carry | zero | sign | overflow | break |
|
||||||
|
| -------- | ------ | -------- | ----- | ---- | ---- | -------- | ----- |
|
||||||
|
| `PUSHF` | `0x2D` | | `-` | `-` | `-` | `-` | `-` |
|
||||||
|
|
||||||
|
#### Description
|
||||||
|
Pushes the current flags on top of the stack. The flags are present in the 4 lowest bits of the result on the stack. In the order *sign*, *zero*, *carry* and *overflow* also represented by the following bit pattern `xxxx xxxx xxxx SZCO`.
|
||||||
|
|
||||||
|
To get the state of a single flag you can use a bit mask.
|
||||||
|
|
||||||
|
example: the operation `flags & 0100` will give a result of 1 if the zero flag was set and a result of 0 if it was unset
|
||||||
|
|
||||||
|
#### Pseudo code
|
||||||
|
```py
|
||||||
|
# 0000 0000 0000 SZCO
|
||||||
|
flags = (SIGN_FLAG << 3) | (ZERO_FLAG << 2) | (CARRY_FLAG << 1) | (OVERFLOW_FLAG)
|
||||||
|
|
||||||
|
SP = SP - 1
|
||||||
|
memory[SP] = flags
|
||||||
|
```
|
||||||
|
|
||||||
### JA
|
### JA
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user