Assembly Language for Beginners

(Jeff_L) #1

1.28 64-bit values in 32-bit environment.


es 0x7b 123
fs 0x0 0
gs 0x33 51
(gdb) bt
#0 0x08048469 in comp ()
#1 0xb7e42872 in msort_with_tmp (p=p@entry=0xbffff07c, b=b@entry=0xbffff0f8, n=n@entry=2)
at msort.c:65
#2 0xb7e4273e in msort_with_tmp (n=2, b=0xbffff0f8, p=0xbffff07c) at msort.c:45
#3 msort_with_tmp (p=p@entry=0xbffff07c, b=b@entry=0xbffff0f8, n=n@entry=5) at msort.c:53
#4 0xb7e4273e in msort_with_tmp (n=5, b=0xbffff0f8, p=0xbffff07c) at msort.c:45
#5 msort_with_tmp (p=p@entry=0xbffff07c, b=b@entry=0xbffff0f8, n=n@entry=10) at msort.c:53
#6 0xb7e42cef in msort_with_tmp (n=10, b=0xbffff0f8, p=0xbffff07c) at msort.c:45
#7 GI_qsort_r (b=b@entry=0xbffff0f8, n=n@entry=10, s=s@entry=4, cmp=cmp@entry=0x804844d <⤦
Çcomp>,
arg=arg@entry=0x0) at msort.c:297
#8 0xb7e42dcf in
GI_qsort (b=0xbffff0f8, n=10, s=4, cmp=0x804844d ) at msort.c:307
#9 0x0804850d in main ()


1.27.3 Danger of pointers to functions


As we can see,qsort()function expects a pointer to function which takes twovoid*arguments and
returning integer. If you have several comparison functions in your code (one compares string, another—
integers, etc), it’s very easy to mix them up with each other. You could try to sort array of string using
function which compares integers, and compiler will not warn you about bug.


1.28 64-bit values in 32-bit environment


In a 32-bit environment,GPR’s are 32-bit, so 64-bit values are stored and passed as 32-bit value pairs^176.


1.28.1 Returning of 64-bit value.


#include <stdint.h>


uint64_t f ()
{
return 0x1234567890ABCDEF;
};


x86


In a 32-bit environment, 64-bit values are returned from functions in theEDX:EAXregister pair.


Listing 1.369: Optimizing MSVC 2010

_f PROC
mov eax, -1867788817 ; 90abcdefH
mov edx, 305419896 ; 12345678H
ret 0
_f ENDP


ARM


A 64-bit value is returned in theR0-R1register pair (R1is for the high part andR0for the low part):


(^176) By the way, 32-bit values are passed as pairs in 16-bit environment in the same way:3.29.4 on page 652

Free download pdf