Jump to content

Host introspection: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 37:
DC.B "LITTLE-ENDIAN",0
EVEN</lang>
=={{header|8086 Assembly}}==
As with [[68000 Assembly]], there's no way to "prove" the word size without knowing it in advance. But endianness can still be tested for quite easily.
<lang asm> .model small
.stack 1024
 
.data
 
UserRam BYTE 256 DUP (0)
 
.code
start:
 
mov ax,@data ;assembler calculates this offset for us
mov ds,ax ;the 8086 can only load segment registers from other registers, not directly from immediate values.
 
mov ax,@code
mov es,ax
 
mov ax,3422h
mov word ptr [ds:UserRam],ax
mov bl, byte ptr [ds:UserRam]
call doMonitor ;a routine that prints the contents of
;the 8086's registers to the screen
 
mov ax,4C00h
int 21h ;return to MS-DOS
 
end start</lang>
 
If the 8086 is little-endian, BX will equal 0022, since we loaded the low byte of UserRam into BL (the low half of BX). If it's big-endian, BX will equal 0034.
 
{{out}}
<pre>
Monitor tools created by Keith of Chibiakumas
AX:3422 BX:0022 CX:00FF DX:0192
F :------I--------- IP:0018
SP:03FA BP:091C DI:0400 SI:0388
CS:01A2 DS:01EC ES:01A2 SS:0425
</pre>
 
From this we conclude that the 8086 is indeed a little-endian CPU.
 
=={{header|Ada}}==
1,489

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.