kvisc/vm/in/ARITH

171 lines
2.8 KiB
Plaintext

# The OS/K Team licenses this file to you under the MIT license.
# See the LICENSE file in the project root for more information.
#---------------------------------------------------------------------------#
# Arithmetic instructions #
#---------------------------------------------------------------------------#
#
# CMP Comparison instruction
#
# $1 - $2
#
# Sets CF if unsigned integer overflow occur, clears it otherwise
# Sets OF is signed integer overflow occur, clears it otherwise
# Sets ZF and SF according to the result
#
cmp r ri
cmp m ri
#
# Arithmetical SGN operation
#
# IF ($1 == 0) THEN
# $2 = 0
# ELIF ($1 GT 0) THEN
# $2 = 1
# ELSE
# $2 = LONG_MIN
# FI
#
# Treats $1 and $2 as signed values
#
# Preserves all flags
#
sgn r r
#
# Arithmetical NEG operation
#
# $1 = NOT($2) + 1
#
# Preserves all flags
#
neg r r
#
# Arithmetical INC operation
#
# $1 = $1 + 1
#
# Preserves all flags
#
inc rm
#
# Arithmetical DEC operation
#
# $1 = $1 - 1
#
# Preserves all flags
#
dec rm
#
# Arithmetical ADD operation
#
# $dest1 = $src1 + $src2
#
# Sets CF if unsigned integer overflow occur, clears it otherwise
# Sets OF is signed integer overflow occur, clears it otherwise
# Sets ZF and SF according to the result
#
add r rim
add r r ri
add m ri
add m r ri
addf r ri
addf r r ri
#
# Atomic exchange and add (XADD)
#
# $tmp = $1
# $1 = $1 + $2
# $2 = $1
#
# Preserves all flags
#
xadd r rm
xadd m r
#
# Arithmetical SUB operation
#
# $dest = $src1 - $src2
#
# Sets CF if unsigned integer overflow occur, clears it otherwise
# Sets OF is signed integer overflow occur, clears it otherwise
# Sets ZF and SF according to the result
#
sub r rim
sub r r ri
sub m ri
sub m r ri
subf r ri
subf r r ri
#
# Arithmetical ADD/SUB operation, with carry/overflow
#
# $dest = $src1 + $src2 + CF (ADC)
# $dest = $src1 + $src2 + OF (ADO)
# $dest = $src1 - $src2 - CF (SBB)
# $dest = $src1 - $src2 - OF (SBO)
#
# Preserves ZF and SF
# Flags CF and OF are undefined for now
#
adc r r
ado r r
sbb r r
sbo r r
#
# Arithmetical unsigned MUL operation
#
# $dest = LO($src1 * $src2)
#
# Preserves ZF and SF
# Sets CF and OF if HI($src1 * $src2) > 0, clears them otherwise
#
mul r ri
mul r r ri
mulf r r ri
# Arithmetical unsigned MUL operation
#
# $dest1 = HI($dest2 * $src)
# $dest2 = LO($dest2 * $src)
#
# Sets CF and OF if HI($2 * $3) > 0, clears them otherwise
# Preserves ZF and SF
#
mulhi r r ri
#
# Arithmetical unsigned DIV operation
#
# $dest1 = $1 DIV $2
#
# Preserves all flags
#
div r ri
div r r ri
#
# Arithmetical unsigned modulo operation (REM)
#
# $1 = $1 MOD $2
#
# Preserves all flags
#
rem r ri
rem r r ri