This is the source code that you can use to start your
program. It is called structure.asm
; Louis Taber PCC 10/31/2004
; Data and subroutine for structure lab.
extern printf
%include "asm_io.inc"
%define UNSIGNED 0x00 ; offsets in structure
%define SIGNED 0x04
%define STRING 0x08
%define OFFSET 2147483648
segment .data
signed_format db " %11d |", 0
unsigned_format db " %10u ", 0
data001 dd 102085 + OFFSET
dd 850
db " *+",0
data002 dd 121
dd -275
db " + *", 0
data003 dd 12
dd 34
db "* +", 0
data004 dd 1343
dd 544
db " * +", 0
data005 dd 14894
dd -189
db " + *", 0
data006 dd 165177 + OFFSET
dd -650
db "+ *", 0
data007 dd 17
dd -50
db " * +", 0
data008 dd 18
dd -27
db " * +", 0
data009 dd 19
dd 136
db " * +", 0
data010 dd 196
dd -108
db " *+", 0
data011 dd 21
dd -125
db " * +", 0
data012 dd 2173
dd -425
db " + *", 0
data013 dd 23
dd -54
db " * +", 0
data014 dd 24099 + OFFSET
dd 748
db " * +", 0
data015 dd 27
dd 238
db " * +", 0
data016 dd 29
dd -200
db " *", 0
data017 dd 317
dd 442
db " * +", 0
data018 dd 3516
dd -162
db " + *", 0
data019 dd 38993 + OFFSET
dd -575
db " + *", 0
data020 dd 46
dd -81
db " * +", 0
data021 dd 513
dd -350
db " + *", 0
data022 dd 5689
dd 646
db " * +", 0
data023 dd 63092 + OFFSET
dd -216
db " + *", 0
data024 dd 75
dd 340
db " * +", 0
data025 dd 830
dd -135
db " + *", 0
data026 dd 9205
dd -500
db " + *", 0
addresses
dd data001,data002,data003,data004
dd data005,data006,data007,data008
dd data009,data010,data011,data012
dd data013,data014,data015,data016
dd data017,data018,data019,data020
dd data021,data022,data023,data024
dd data025,data026,0
header db "Louis Taber, PCC Structures",13,10,13,10,0
segment .text
global asm_main
asm_main:
enter 0,0 ; setup routine
pusha
mov eax, header ; print out header
call print_string
mov eax, addresses
call print_s ; print out strings.
popa
mov eax, 0 ; return back to C
leave
ret
print_s: ; eax start of list
pusha
mov edx,eax
loop1:
mov ebx, [edx] ; Place structure address in eax
cmp ebx,0 ; There is a zero at the end of the list
je return
mov eax, [ebx+UNSIGNED]
; Get unsigned number
call print_unsigned
; Print
mov eax, [ebx+SIGNED]
; Get signed number
call print_signed ; Print
lea eax, [ebx+STRING]
; Get the address of the string
call print_string
; Print it.
call print_nl ; Add a new line
add edx,4 ; Point to the next address
jmp loop1 ; Do it again -- till the end.
return:
popa
ret
print_signed: ; Print eax as a signed number
enter 0,0 ; set up stack frame
pusha ; save all gp registers
pushf ; save flags
push eax ; pass eax by value
push dword signed_format
; pass format string
call printf ; call "C" printf
pop ecx ; clear stack of passed values (format)
pop ecx ; clear stack of passed values eax
popf ; restore flags
popa ; restore all gp registers and
; -- destroy returned eax from printf
leave ; Release stack frame
ret
print_unsigned: ; Print eax as a unsigned number
enter 0,0 ; set up stack frame
pusha ; save all gp registers
pushf ; save flags
push eax ; pass eax by value
push dword unsigned_format
; pass format string
call printf ; call "C" printf
pop ecx ; clear stack of passed values (format)
pop ecx ; clear stack of passed values eax
popf ; restore flags
popa ; restore all gp registers and
; -- destroy returned eax from printf
leave ; Release stack frame
ret