rdos/lib/nasmcomp.asm
2020-03-01 12:03:35 +00:00

125 lines
3.1 KiB
NASM

; Pseudo-Instruction: fill bytes until offset
%macro pad 1.nolist
times (%1 - ($-$$)) nop
%endmacro
; REGISTERS
%define a al
%define b ch
%define c cl
%define d dh
%define e dl
%define h bh
%define l bl
%define m byte [bx]
; REGISTER PAIRS
%define bc cx
%define de dx
%define hl bx
; INSTRUCTIONS
; data movement
; 'mov' can stay literal
%define mvi mov
%define lxi mov
%macro lda 1
mov al, byte [%1]
%endmacro
%macro sta 1
mov byte [%1], al
%endmacro
%macro lhld 1
mov bx, word [%1]
%endmacro
%macro shld 1
mov word [%1], bx
%endmacro
%macro ldax 1
mov al, byte [%1]
%endmacro
%macro stax 1
mov byte [%1], al
%endmacro
%macro xchg 1
xchg dx, bx
%endmacro
; addition
%macro add 1
add al, %1
%endmacro
%macro adi 1
add al, %1
%endmacro
%macro adc 1
adc al, %1
%endmacro
%macro aci 1
adc al, %1
%endmacro
; subtraction
%macro sub 1
sub al, %1
%endmacro
%macro sui 1
sub al, %1
%endmacro
%macro sbb 1
sub al, %1
%endmacro
%macro sbi 1
sub al, %1
%endmacro
; increment / decrement
%define inr inc
%define dcr dec
%define inx inc
%define dcx dec
; pointer arithmetic
%macro dad 1
add bx, %1
%endmacro
; 'daa' stays literal
;ANA S 10100SSS ZSCPA AND register with A
;ANI # 11100110 db ZSPCA AND immediate with A
;ORA S 10110SSS ZSPCA OR register with A
;ORI # 11110110 ZSPCA OR immediate with A
;XRA S 10101SSS ZSPCA ExclusiveOR register with A
;XRI # 11101110 db ZSPCA ExclusiveOR immediate with A
;CMP S 10111SSS ZSPCA Compare register with A
;CPI # 11111110 ZSPCA Compare immediate with A
;RLC 00000111 C Rotate A left
;RRC 00001111 C Rotate A right
;RAL 00010111 C Rotate A left through carry
;RAR 00011111 C Rotate A right through carry
;CMA 00101111 - Compliment A
;CMC 00111111 C Compliment Carry flag
;STC 00110111 C Set Carry flag
;JMP a 11000011 lb hb - Unconditional jump
;Jccc a 11CCC010 lb hb - Conditional jump
;CALL a 11001101 lb hb - Unconditional subroutine call
;Cccc a 11CCC100 lb hb - Conditional subroutine call
;RET 11001001 - Unconditional return from subroutine
;Rccc 11CCC000 - Conditional return from subroutine
;RST n 11NNN111 - Restart (Call n*8)
;PCHL 11101001 - Jump to address in H:L
;PUSH RP 11RP0101 *2 - Push register pair on the stack
;POP RP 11RP0001 *2 *2 Pop register pair from the stack
;XTHL 11100011 - Swap H:L with top word on stack
;SPHL 11111001 - Set SP to content of H:L
;IN p 11011011 pa - Read input port into A
;OUT p 11010011 pa - Write A to output port
;EI 11111011 - Enable interrupts
;DI 11110011 - Disable interrupts
;HLT 01110110 - Halt processor
;NOP 00000000 - No operation
%macro cnz 1
jz %%skip
call near %1
%%skip:
%endmacro