diff --git a/src/constants.asm b/src/constants.asm index fd30701..5fe0666 100644 --- a/src/constants.asm +++ b/src/constants.asm @@ -21,3 +21,23 @@ section .rodata SIZE_DWORD equ 4 SIZE_WORD equ 2 SIZE_BYTE equ 1 + + MIN_UINT64 equ 0 + MIN_UINT32 equ 0 + MIN_UINT16 equ 0 + MIN_UINT8 equ 0 + + MAX_UINT64 equ 0xFFFFFFFFFFFFFFFF + MAX_UINT32 equ 0xFFFFFFFF + MAX_UINT16 equ 0xFFFF + MAX_UINT8 equ 0xFF + + MIN_INT64 equ ~0x7FFFFFFFFFFFFFFF + MIN_INT32 equ ~0x7FFFFFFF + MIN_INT16 equ ~0x7FFF + MIN_INT8 equ ~0x7F + + MAX_INT64 equ 0x7FFFFFFFFFFFFFFF + MAX_INT32 equ 0x7FFFFFFF + MAX_INT16 equ 0x7FFF + MAX_INT8 equ 0x7F diff --git a/src/tests.asm b/src/tests.asm index d681084..9df0d36 100644 --- a/src/tests.asm +++ b/src/tests.asm @@ -46,6 +46,7 @@ section .rodata TEST_strcmp equ 1 TEST_min equ 0 ;includes minu TEST_max equ 0 ;includes maxu + TEST_clamp equ 1 ;includes clampu str1 db "Hello, world!",EOS str2 db "Hello, World!",EOS @@ -189,6 +190,19 @@ section .rodata maxu2 db TAB,"maxu(-15, -30):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS maxu3 db TAB,"maxu(-1, 0):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS maxu4 db TAB,"maxu(0xFFFFFFFF, -4294967295):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS + + ; clamp() / clampu() + msgClamp db NL,"clampArg1 = MIN_INT32, clampArg2 = MAX_INT32",NL,"clampuArg1 = MIN_UINT32, clampuArg2 = MAX_UINT32",NL,"TEST clamp(), clampu()",NL,EOS + clampArg1 equ MIN_INT32 + clampArg2 equ MAX_INT32 + clamp1 db TAB,"clamp(MIN_INT64, clampArg1, clampArg2): %d",NL,EOS + clamp2 db TAB,"clamp(MAX_INT64, clampArg1, clampArg2): %d",NL,EOS + clamp3 db TAB,"clamp(MAX_UINT16, clampArg1, clampArg2): %d",NL,EOS + clamp4 db TAB,"clamp(MAX_INT32+1, clampArg1, clampArg2): %d",NL,EOS + clampuArg1 equ MIN_UINT32 + clampuArg2 equ MAX_UINT32 + clampu1 db TAB,"clampu(MAX_UINT64, clampArg1, clampArg2): %d",NL,EOS + clampu2 db TAB,"clampu(MAX_UINT16, clampArg1, clampArg2): %d",NL,EOS section .data section .bss @@ -1004,6 +1018,65 @@ _start: call printf %endif +;--- +;--- clamp() / clampu() +;--- +%if TEST_clamp + lea rdi, [rel msgClamp] + call print + + ; TEST 1 + mov rdi, MIN_INT64 + mov rsi, clampArg1 + mov rdx, clampArg2 + call clamp + mov rsi, rax + lea rdi, [rel clamp1] + call printf + ; TEST 2 + mov rdi, MAX_INT64 + mov rsi, clampArg1 + mov rdx, clampArg2 + call clamp + mov rsi, rax + lea rdi, [rel clamp2] + call printf + ; TEST 3 + mov rdi, MAX_UINT16 + mov rsi, clampArg1 + mov rdx, clampArg2 + call clamp + mov rsi, rax + lea rdi, [rel clamp3] + call printf + ; TEST 4 + mov rdi, MAX_INT32+1 + mov rsi, clampArg1 + mov rdx, clampArg2 + call clamp + mov rsi, rax + lea rdi, [rel clamp4] + call printf + + ; TEST 5 + mov rdi, MAX_UINT64 + mov rsi, clampuArg1 + mov rdx, clampuArg2 + call clampu + mov rsi, rax + lea rdi, [rel clampu1] + call printf + + ; TEST 6 + mov rdi, MAX_UINT16 + mov rsi, clampuArg1 + mov rdx, clampuArg2 + call clampu + mov rsi, rax + lea rdi, [rel clampu2] + call printf +%endif + ;--- ;--- exit() ;---