I'm new in nasm and i have some questions :) 
Author Message
 I'm new in nasm and i have some questions :)

Is there any 'array' thing in NASM? Also how can i define structures? Is
structures the same thing as the 'records' in Pascal?

thanx,
Bad Sector



Sat, 02 Nov 2002 03:00:00 GMT  
 I'm new in nasm and i have some questions :)

Quote:

>Is there any 'array' thing in NASM?

No.  You don't need arrays in assembly - just reserve a big enough
block of memory.

Quote:
>Also how can i define structures?

See sections 4.7.3 and 4.7.4 of the NASM manual.

Quote:
>Is structures the same thing as the 'records' in Pascal?

Yes.

S.



Sat, 02 Nov 2002 03:00:00 GMT  
 I'm new in nasm and i have some questions :)

Quote:

> Is there any 'array' thing in NASM? Also how can i define structures? Is
> structures the same thing as the 'records' in Pascal?

Steamer's given you the short answer, but some of us (like me) like
examples. Betov won't like this code - I don't much like it myself - but
it's devised to use both structures and an array of pointers to
structures - not necessarily correctly or appropriately.

Best,
Frank

;--------------------------------------
; nasm -f bin -o bshello.com bshello.asm
; stands for Bios, and Structure, not what you think

org 100h

                  ; a structure...
struc my_msg
    row          resb 1
    column       resb 1
    color        resb 1
    msg_text_ptr resw 1
    msg_len      resw 1
endstruc

segment .data

                  ; some strings, and their lengths

    msg1 db 'Hello'
    msg1_len equ $-msg1

    msg2 db ', '
    msg2_len equ $-msg2

    msg3 db 'World'
    msg3_len equ $-msg3

    msg4 db '!'
    msg4_len equ $-msg4

          ; initialize some instances of our structure

    my_msg1 istruc my_msg
        at row,          db 12
        at column,       db 34
        at color,        db 7
        at msg_text_ptr, dw msg1
        at msg_len,      dw msg1_len
    iend

    my_msg2 istruc my_msg
        at row,          db 12
        at column,       db 39
        at color,        db 1
        at msg_text_ptr, dw msg2
        at msg_len,      dw msg2_len
    iend

    my_msg3 istruc my_msg
        at row,          db 12
        at column,       db 41
        at color,        db 3
        at msg_text_ptr, dw msg3
        at msg_len,      dw msg3_len
    iend

    my_msg4 istruc my_msg
        at row,          db 12
        at column,       db 46
        at color,        db 84h
        at msg_text_ptr, dw msg4
        at msg_len,      dw msg4_len
    iend

             ; an array of pointers to 'em

    msg_ptrs dw my_msg1, my_msg2, my_msg3, my_msg4

segment .text

    mov ax, 3                 ; lazy cls
    int 10h

    xor bx, bx
    mov cx, 4                 ; print 4 messages
print_loop:
    lea si, [msg_ptrs + bx]   ; get our array element
    mov si, [si]              ; it's a pointer!
    call print_my_msg
    add bx, 2                 ; word array!
    loop print_loop

    mov ah, 4Ch
    int 21h

;------------------------------
; expects ds = es = data
;         si -> structure
;------------------------------
print_my_msg:
    push ax
    push bx
    push cx
    push dx
    push bp

    mov ax, 1300h               ; print string
    mov bp, [si + msg_text_ptr] ; note - expects ES:bp !
    mov bl, [si + color]
    xor bh, bh                  ; video page zero
    mov cx, [si + msg_len]
    mov dh, [si + row]
    mov dl, [si + column]
    int 10h

    pop bp
    pop dx
    pop cx
    pop bx
    pop ax
    ret
;---------



Sun, 03 Nov 2002 03:00:00 GMT  
 I'm new in nasm and i have some questions :)
Hi, Frank.

Your exemple is not so bad. This is the case in witch structures
are the less "blamable". But, as you certainely know (if i have
well understood some of your previous messages), if the declarations
were written without structure, and the adresses of the four data
sets retrieved in a simple Pointers table, the only difference is
that it would be shorter to write and easier to read (not less
structured or abstract or powerfull in anyway):

    msg1:              db 'Hello', 0
    msg1_len           equ $-msg1
    msg1_row:          db 12
    msg1_column:       db 34
    msg1_color:        db 7

    msg2:              db ', ', 0
    msg2_len           equ $-msg2
    msg2_row:          db 12
    msg2_column:       db 39
    msg2_color:        db 1

    msg3:              db 'World', 0
    msg3_len           equ $-msg3
    msg3_row:          db 12
    msg3_column:       db 41
    msg3_color:        db 3

    msg4:              db '!', 0
    msg4_len           equ $-msg4
    msg4_row:          db 12
    msg4_column:       db 46
    msg4_color:        db 84

    MessagesTable:     DW msg1
                       DW msg2
                       DW msg3
                       DW msg4

Bye. betov.

Frank Kotler a crit :

Quote:

> > Is there any 'array' thing in NASM? Also how can i define structures? Is
> > structures the same thing as the 'records' in Pascal?

> Steamer's given you the short answer, but some of us (like me) like
> examples. Betov won't like this code - I don't much like it myself - but
> it's devised to use both structures and an array of pointers to
> structures - not necessarily correctly or appropriately.

> Best,
> Frank

> ;--------------------------------------
> ; nasm -f bin -o bshello.com bshello.asm
> ; stands for Bios, and Structure, not what you think

> org 100h

>                   ; a structure...
> struc my_msg
>     row          resb 1
>     column       resb 1
>     color        resb 1
>     msg_text_ptr resw 1
>     msg_len      resw 1
> endstruc

> segment .data

>                   ; some strings, and their lengths

>     msg1 db 'Hello'
>     msg1_len equ $-msg1

>     msg2 db ', '
>     msg2_len equ $-msg2

>     msg3 db 'World'
>     msg3_len equ $-msg3

>     msg4 db '!'
>     msg4_len equ $-msg4

>           ; initialize some instances of our structure

>     my_msg1 istruc my_msg
>         at row,          db 12
>         at column,       db 34
>         at color,        db 7
>         at msg_text_ptr, dw msg1
>         at msg_len,      dw msg1_len
>     iend

>     my_msg2 istruc my_msg
>         at row,          db 12
>         at column,       db 39
>         at color,        db 1
>         at msg_text_ptr, dw msg2
>         at msg_len,      dw msg2_len
>     iend

>     my_msg3 istruc my_msg
>         at row,          db 12
>         at column,       db 41
>         at color,        db 3
>         at msg_text_ptr, dw msg3
>         at msg_len,      dw msg3_len
>     iend

>     my_msg4 istruc my_msg
>         at row,          db 12
>         at column,       db 46
>         at color,        db 84h
>         at msg_text_ptr, dw msg4
>         at msg_len,      dw msg4_len
>     iend

>              ; an array of pointers to 'em

>     msg_ptrs dw my_msg1, my_msg2, my_msg3, my_msg4

> segment .text

>     mov ax, 3                 ; lazy cls
>     int 10h

>     xor bx, bx
>     mov cx, 4                 ; print 4 messages
> print_loop:
>     lea si, [msg_ptrs + bx]   ; get our array element
>     mov si, [si]              ; it's a pointer!
>     call print_my_msg
>     add bx, 2                 ; word array!
>     loop print_loop

>     mov ah, 4Ch
>     int 21h

> ;------------------------------
> ; expects ds = es = data
> ;         si -> structure
> ;------------------------------
> print_my_msg:
>     push ax
>     push bx
>     push cx
>     push dx
>     push bp

>     mov ax, 1300h               ; print string
>     mov bp, [si + msg_text_ptr] ; note - expects ES:bp !
>     mov bl, [si + color]
>     xor bh, bh                  ; video page zero
>     mov cx, [si + msg_len]
>     mov dh, [si + row]
>     mov dl, [si + column]
>     int 10h

>     pop bp
>     pop dx
>     pop cx
>     pop bx
>     pop ax
>     ret
> ;---------



Sun, 03 Nov 2002 03:00:00 GMT  
 I'm new in nasm and i have some questions :)

Quote:

> Your exemple is not so bad. This is the case in witch structures
> are the less "blamable". But, as you certainely know (if i have
> well understood some of your previous messages), if the declarations
> were written without structure, and the adresses of the four data
> sets retrieved in a simple Pointers table, the only difference is
> that it would be shorter to write and easier to read (not less
> structured or abstract or powerfull in anyway):

Agreed. You raise a good point here: "structured programming" and
using/not using "data structures" (whether they're called "struct" or
"struc") are two entirely different things. "data structures" are just
an alternative way to attach names, perhaps meaningful names, to
offsets. I'll not attempt a definition of "structured programming".

Best,
Frank



Sun, 03 Nov 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Having trouble with NASM's times pseudo-op

2. New official netwide assembler (NASM) mailing list -- NASM Advocate

3. NASM and nasm.sl for JED editor mode question

4. having trouble 'making' XF

5. Hash.new(Hash.new) doesn't use Hash.new as default value

6. NASM: Trouble with the 'IMPORT' directive

7. Need help linking NASM .obj's to C++ obj's

8. New to LabView... but having some requirements

9. New user.............(still having problems)

10. New eiffel user having problems with elif

11. File.new : having problems in windows

12. New to Cobol and Having Problwm w/Pgm

 

 
Powered by phpBB® Forum Software