This is a mod of my earlier post.
I'm running on 32-bit Fedora 9 Linux, programming an app that requires 64-bit ints and floats.
I changed both maxofthree.asm and callmaxofthree.c (see below) to use use 64-bit args but got this nasm compilation listing:
[michael@localhost ~]$ !na
nasm -f elf maxofthree.asm -o maxofthree.o
maxofthree.asm:16: error: invalid operands in non-64-bit mode
maxofthree.asm:17: error: invalid operands in non-64-bit mode
maxofthree.asm:18: error: invalid operands in non-64-bit mode
maxofthree.asm:19: error: invalid operands in non-64-bit mode
maxofthree.asm:20: error: invalid operands in non-64-bit mode
maxofthree.asm:21: error: invalid operands in non-64-bit mode
maxofthree.asm:22: error: invalid operands in non-64-bit mode
[michael@localhost ~]$
Looked in the nasm docs and found the 64 BIT directive but wasn't sure about its placement. In any case, rather than fix the problem, it told me that 64 BIT wasn't supported for elf. Time to surrender, or am I missing something?
Michael
========================================
* callmaxofthree.c
*
* Illustrates how to call the maxofthree function we wrote in assembly
* language.
*/
#include
long long int maxofthree(long long int, long long int, long long int);
int main() {
printf("%ll\n", maxofthree(1LL, -4LL, -7LL));
printf("%ll\n", maxofthree(2LL, -6LL, 1LL));
printf("%ll\n", maxofthree(2LL, 3LL, 1LL));
printf("%ll\n", maxofthree(-2LL, 4LL, 3LL));
printf("%ll\n", maxofthree(2LL, -6LL, 5LL));
printf("%ll\n", maxofthree(2LL, 4LL, 6LL));
return 0;
}
; ----------------------------------------------------------------------------
; maxofthree.asm
;
; NASM implementation of a function that returns the maximum value of its
; three long long integer parameters. The function has prototype:
;
; long long int maxofthree(long long int x, long long int y, long long int z)
;
; Note that only rax, rcx, and rdx were used so no registers had to be saved
; and restored.
; ----------------------------------------------------------------------------
global maxofthree
section .text
maxofthree:
mov rax, [esp+4]
mov rcx, [esp+8]
mov rdx, [esp+12]
cmp rax, rcx ;if rax < rcx
cmovl rax, rcx ; rax <- rcx
cmp rax, rdx ;if rax < rdx
cmovl rax, rdx ; rax <- rdx
ret