Enumerations: Difference between revisions

Line 118:
MOVE.L (A1),A1 ;dereference the pointer, now the address of "Thursday" is in A1.
MOVE.B (A1)+,D1 ;Load the "T" of Thursday into D1, auto-increment to next letter for the next load.</lang>
 
=={{header|8086 Assembly}}==
{{trans|6502 Assembly}}
===With Explicit Values===
Most assemblers allow the use of an <code>equ</code> directive or something similar, where you can assign a label to a number for later use. These do not take up space in your program.
<lang asm>Sunday equ 0
Monday equ 1
Tuesday equ 2
Wednesday equ 3
Thursday equ 4
Friday equ 5
Saturday equ 6
Sunday equ 7</lang>
 
===Without Explicit Values===
A lookup table is often used to translate data according to a common index. The <code>XLAT</code> instruction can help us with this task, however that instruction only works with 8-bit data, which is not always what we're after. In this example, we're using numbers 0 through 7 to look up a table of pointers to strings. When declaring a table like this, these DO take up space in your program.
<lang asm>mov ax,seg DaysOfTheWeek
mov ds,ax
mov si,offset DaysOfTheWeek
 
mov bx,2 ;desired enumeration of 2 = Tuesday
add bx,bx ;double bx since this is a table of words
mov ax,[bx+si] ;load the address of the string "Tuesday" into ax
mov si,ax ;we can't load indirectly from AX, so move it into SI. We don't need the old value of SI anymore
mov al,[si] ;load the byte at [SI] (in this case, the "T" in Tuesday.)
ret
 
DaysOfTheWeek word Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday
;each is a pointer to a string containing the text you would expect.</lang>
 
 
=={{header|ACL2}}==
1,489

edits