Help with structure
I found this example.
I can't figure out how to use the data that has been put into the
structure. Like to print out the string and number.
Thanks.
Storage STRUC
TEXT db ' '
Nummer dw ?
Sieben dw ?
Storage ENDS
.data
Keeper Moat <'Customer',41,44700> ; initialize the structure
.code
start:
mov ax,@data
mov ds,ax
; fill structure
mov ax,Keeper.Nummer
mov bx,offset Keeper
mov ax,word ptr [bx.Sieben]
exit:
mov ax,4c00h
int 21h
end start
[864 byte] By [
Slider7] at [2007-11-20 8:29:09]

# 1 Re: Help with structure
If my memory not fails me this is good old DOS assembly but maybe it still works in a 32 bit shell?
It's good to be nostalgic and save stuff sometimes! :)
Directly from the book "The Waite Group's MS_DOS Developers Guide":
Int21, function 02h - Output Character to Console
AH=02h
ENTRY: DL = Character to write to console
RETURN: None
Int21, function 09h - Output String to Console
AH=09h
ENTRY: DS:DX = Pointer to string terminated by $
RETURN: None
So make sure the string is terminated with a $ and then it's trivial to print it to console.
The numbers you have to translate to characters, maybe easiest to start off by printing the numbers as hex.
S_M_A at 2007-11-10 3:55:17 >

# 2 Re: Help with structure
Sorry I wasn't clear enough. I need to know how to put the structure info into the registers for processing.
For now, just puting the 41 that is in Nummer would be fine.
# 3 Re: Help with structure
But you already do that...
Storage STRUC
TEXT db ' ' ; Replace ' ' with a number to allocate more bytes
Nummer dw ?
Sieben dw ?
Storage ENDS
.data
;I think Moat should be Storage by the way
Keeper Moat <'Customer',41,44700> ; initialize the structure
.code
start:
mov ax,@data
mov ds,ax
; fill structure
mov ax,Keeper.Nummer ;This copies the value of Keeper.Nummer to ax
mov bx,offset Keeper ; This copies the address (pointer) to structure
mov ax,word ptr [bx.Sieben] ; This copies first bytes from Keeper.TEXT
exit:
mov ax,4c00h
int 21h
end start
I would do (don't remember full syntax so you probably will have some issues to fix)
Storage STRUC
TEXT db 20
Nummer dw 1
Sieben dw 1
Storage ENDS
.data
Keeper Storage <'Customer$',41,44700> ; initialize the structure
.code
start:
mov ax,@data
mov ds,ax
;print string to console
mov bx, offset Keeper.TEXT
mov dx, offset Keeper.TEXT
mov ah,09h
int 21h
;Print number
mov bx, offset Keeper.Nummer
mov cx, 4 ;Or 2 maybe?
nxt:
mov dl, byte ptr [bx]
call ConvertDlFromBinToHex
mov ah,02h
int 21h
inc bx
repnz nxt ;Or what it was called the instr that decr cx for auto loop
exit:
mov ax,4c00h
int 21h
end start
S_M_A at 2007-11-10 3:57:19 >

# 4 Re: Help with structure
Thanks S.M.A. for your patience.
This prints the last two letters of String.
It's better than my earlier attempts which were beeping all over
the place.
Moat STRUC
TEXT db ' '
Nummer dw ?
Sieben dw ?
Moat ENDS
.data
; Text Word Value Word Value
Keeper Moat <'String$',41,44700> ; initialize the structure
.code
start:
mov ax,@data
mov ds,ax
; fill structure
mov ax,Keeper.Nummer ; 41 decimal = 29 in hex
mov bx,offset Keeper
mov ax,word ptr [bx.Sieben]
mov dx,offset [bx.Nummer]
mov ah,9
int 21h
exit:
mov ax,4c00h
int 21h
end start
# 5 Re: Help with structure
Your welcome slider, fun to see some assembler again. A pity I don't remember that much though.
What assembler do you use? Tried to use the Studio2005 masm but have failed not succeed with the build so far.
Slider when posting code here, use code tags. Code will be simpler to read and also formatting will stay. All you have to do is to place a [ code] before the code starts and [ /code] after the code ends. Remove the space within the [] example though.
S_M_A at 2007-11-10 3:59:14 >

# 6 Re: Help with structure
I found what seems to be a good assembly learning site http://kipirvine.com/asm/
Site has a lot of examples and ready-to-use routines
S_M_A at 2007-11-10 4:00:21 >

# 7 Re: Help with structure
Your welcome slider, fun to see some assembler again. A pity I don't remember that much though.
What assembler do you use? Tried to use the Studio2005 masm but have failed not succeed with the build so far.
Slider when posting code here, use code tags. Code will be simpler to read and also formatting will stay. All you have to do is to place a [ code] before the code starts and [ /code] after the code ends. Remove the space within the [] example though.
I use primarily tasm, but sometimes have to use 16 bit masm.
It's been real hard finding source code for structures in either language.
Since 32 bit also uses structures, I will benefit from learning it.
# 8 Re: Help with structure
Whoa, thought about bying that book just for the fun of reviving old days but... almost $100!!! Think I first look for another book...
S_M_A at 2007-11-10 4:02:21 >

# 9 Re: Help with structure
Just couldn't resist it... Take it for what it is but now it at least works in some way. I used the tools from the site I pointed out to build it for 16 bit DOS.
.model small,STDCALL
.stack 200h
.386
.DOSSEG
STRING_LEN equ 20
Moat STRUC
text db STRING_LEN dup (?)
Nummer dw ?
Sieben dw ?
Moat ENDS
.data
Keeper Moat <'String$',41,44700> ; initialize the structure
.code
; Converts bin value in low nibble of dl to ASCII hex in dl
BinToHex PROC
cmp dl, 9
ja hex
add dl, '0'
ret
hex:
add dl, 'A'-10
ret
BinToHex ENDP
main PROC
mov ax, @data
mov ds, ax
; Print string
mov dx, offset Keeper.text
mov ah, 9
int 21h
; Print Nummer
mov ax, ds
mov es, ax
mov bx, offset Keeper.Nummer
mov cx, 12
next:
mov dx, WORD PTR [bx]
shr dx, cl
and dx, 0Fh
call BinToHex
mov ah, 2
int 21h
cmp cx, 0
je done
sub cx, 4
jmp next
done:
.EXIT
main ENDP
END main
S_M_A at 2007-11-10 4:03:20 >

# 10 Re: Help with structure
This is what I get when I ran your code.
The 29 is the hex value. Is that what you wanted output?
The compiler doesn't know the 41 is a number, so another routine
would be needed.
String0029
I looked at that package. It's pretty interesting. There is a lot of code scattered around, but there are plenty of examples.
I have found about 90% of the 16 bit source code on the net is
tasm code.
# 11 Re: Help with structure
Yes 0029 is as expected. I just wanted to use those two DOS services I mentioned in first post so I made a hex printout instead of a decimal one.
S_M_A at 2007-11-10 4:05:24 >

# 12 Re: Help with structure
This is supposed to convert binary to ASCII but it isn't working right.
Maybe I am misundertanding what it does.
/code
.data
Keeper Moat <'String$',15,44700> ; initialize the structure
.code
; Converts bin value in low nibble of dl to ASCII hex in dl
BinToHex PROC
cmp dl, 9
ja hex
add dl, '0'
ret
hex:
add dl, 'A'-10
ret
BinToHex ENDP
main PROC
mov ax, @data
mov ds, ax
; AL must be 0..F (0 - 15 decimal)
;
; mov al,15
; cmp al,0ah
; sbb al,69h
; das
; int 29h
; Print string
mov dx, offset Keeper.text
mov ah, 9
int 21h
; Print Nummer
mov ax, ds
mov es, ax
mov bx, offset Keeper.Nummer
mov cx, 12
next:
mov dx, WORD PTR [bx]
shr dx, cl
and dx, 0Fh
call BinToHex
mov ah, 2
int 21h
cmp cx, 0
je done
sub cx, 4
jmp next
done:
mov ax,ds
mov es,ax
mov ax, offset Keeper.Sieben
int 3 ; look at what's going on
xor ah,ah ; Convert binary to ASCII
cmp al,0ah
sbb al,69h
das
int 29h
.EXIT
/code
# 13 Re: Help with structure
You almost got it right with the code tags, the tag before post shall not have leading / and both tags shall be within []. Press edit and try it out.
Where did you get that conversion method? I ran it and it outputs a G instead of the expected 0. To bad I thrown away all my 16 bit tools. Can't run it in debugger to see what's happening.
S_M_A at 2007-11-10 4:07:26 >

# 14 Re: Help with structure
You almost got it right with the code tags, the tag before post shall not have leading / and both tags shall be within []. Press edit and try it out.
Where did you get that conversion method? I ran it and it outputs a G instead of the expected 0. To bad I thrown away all my 16 bit tools. Can't run it in debugger to see what's happening.
What OS are you running ?
I have TONS of code that I have found and store. I study it when I have time.
I have a 32 bit command line debugger that works in a WinXP window.
If you would like the source code, lemme know. Most of it is tasm code, but
it's fairly easy to convert to masm. Some of it is masm.
Do you write 32 bit code ?
I made a dll plugin and it works fine, but need a little help with it.
The code is very short.
Later,
Andy
# 15 Re: Help with structure
I run XP Prof.
32-bit works fine to debug in my Studio2005 and I found an old CodeView 3.14 so now I can debug 16-bit also (without symbols so far).
I haven't done anything for PC in assembly for the last 15 years or so. Back then I used it for making TSRs and in some need-for-speed situations.
Sure post it but use code tags ;), I'll do my best to help. It's fun to revive old knowledge.
By the way, that convert binary to ASCII snippet you added to the code only converts values in the range 0-9.
S_M_A at 2007-11-10 4:09:29 >

# 16 Re: Help with structure
Errors trying to post code . Have attached file.
# 17 Re: Help with structure
Sorry slider, had to work late today and unfortunately I didn't open your post at work. Thought it should take awhile to help you.
About posting code. There's no edit button for making a new post. Edit is for editing a post that you already has made. When posting code you do the same as posting a message, press 'post reply', type what you want and then cut&paste your code into the text but inbetween the tags [code*] and [/code*] (stars should be removed though).
To change the name of the library you only have to change the LIBRARY statement in the def-file.
S_M_A at 2007-11-10 4:11:32 >

# 18 Re: Help with structure
Thanks.
Things have been busy for me.
I am seeking a technical writer position. In the meantime, I do
home repair and remodeling jobs.
Andy