mirror of
https://gitlab.os-k.eu/os-k-team/kvisc.git
synced 2023-08-25 14:05:46 +02:00
130 lines
2.8 KiB
Plaintext
130 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.
|
|
|
|
#---------------------------------------------------------------------------#
|
|
# String manipulation instructions #
|
|
#---------------------------------------------------------------------------#
|
|
|
|
#
|
|
# Store value into string (STOSx)
|
|
#
|
|
# [%1] = $2
|
|
# IF (DF == 0) THEN
|
|
# %str = %str + sizeof(x)
|
|
# ELSE
|
|
# %str = %str - sizeof(x)
|
|
# FI
|
|
#
|
|
# When no parameters are given, %str = RDI and $val = RAX
|
|
# When one parameter is given, %str = RDI and $val = $1
|
|
# When two parameters are given, %str = $1 and $val = $2
|
|
#
|
|
stosb r ri
|
|
stosw r ri
|
|
stosl r ri
|
|
stosq r ri
|
|
|
|
#
|
|
# Load value from string (LODSx)
|
|
#
|
|
# $1 = [%2]
|
|
# IF (DF == 0) THEN
|
|
# %str = %str + sizeof(x)
|
|
# ELSE
|
|
# %str = %str - sizeof(x)
|
|
# FI
|
|
#
|
|
# Preserves CF, OF and SF
|
|
# Sets ZF according to the loaded value
|
|
#
|
|
lodsb r r
|
|
lodsw r r
|
|
lodsl r r
|
|
lodsq r r
|
|
|
|
#
|
|
# Scan string for a particular value (SCASx)
|
|
#
|
|
# CMP([%1], $2)
|
|
#
|
|
# IF ([%1] == 0) THEN
|
|
# ZF = 1
|
|
# ELIF (ZF == 0) THEN
|
|
# IF (DF == 0) THEN
|
|
# %1 = %1 + sizeof(x)
|
|
# ELSE
|
|
# %1 = %1 - sizeof(x)
|
|
# FI
|
|
# FI
|
|
#
|
|
# Sets CF, OF and SF according to the result of the comparison
|
|
# Sets ZF according to whether [%1] and $2 are equal, OR if [%1] is null
|
|
#
|
|
# Notes:
|
|
# - Does not move past the value when found
|
|
# - 'SCASB.REP.NZ reg ch' is a short 'strchnul()'
|
|
#
|
|
scasb r ri
|
|
scasw r ri
|
|
scasl r ri
|
|
scasq r ri
|
|
|
|
#
|
|
# Compare bytes in strings (CMPSx)
|
|
#
|
|
# CMP([%1], [%2])
|
|
#
|
|
# IF (DF == 0) THEN
|
|
# %1 = %1 + sizeof(x)
|
|
# %2 = %2 + sizeof(x)
|
|
# ELSE
|
|
# %1 = %1 - sizeof(x)
|
|
# %2 = %2 - sizeof(x)
|
|
# FI
|
|
#
|
|
# Sets CF, OF, ZF and SF according to the result of the comparison
|
|
#
|
|
# Moves past the compared values in any case!
|
|
#
|
|
cmpsb r r
|
|
cmpsw r r
|
|
cmpsl r r
|
|
cmpsq r r
|
|
|
|
#
|
|
# Safe compare bytes in strings (CMPZSx)
|
|
#
|
|
# Behaves precisely like CMPSx, except in the following case:
|
|
# - If both [%1] and [%2] are zero, clears ZF (indicating NOT EQUAL)
|
|
#
|
|
# This prevents 'CMPZSx.REP.Z' from looping infinitely when both strings
|
|
# have the exact same content; this allows for short strcmp's
|
|
#
|
|
cmpzsb r r
|
|
cmpzsw r r
|
|
cmpzsl r r
|
|
cmpzsq r r
|
|
|
|
#
|
|
# Move value from string to string (MOVSx)
|
|
#
|
|
# [%1] = [%1]
|
|
# IF (DF == 0) THEN
|
|
# %1 = %1 + sizeof(x)
|
|
# %2 = %2 + sizeof(x)
|
|
# ELSE
|
|
# %1 = %1 - sizeof(x)
|
|
# %2 = %2 - sizeof(x)
|
|
# FI
|
|
#
|
|
# Preserves CF, OF and SF
|
|
# Sets ZF according to the moved value
|
|
#
|
|
movsb r r
|
|
movsw r r
|
|
movsl r r
|
|
movsq r r
|
|
|
|
#---------------------------------------------------------------------------#
|
|
|