Assembler: Nasm
I want to: Learn to use uninitialized variables declared in .bss

I know that you can create an variable with resb and I know how to put a value ..... I think I just figured out how to do what I was asking. I'll give a snippet as to what I was thinking and you guys tell me if that is how to populate an array.

array resb 10; create a 10 character array

mov ,01      ;array[1] = 1
mov ,2  ;array[2] = 2

If the above is correct then can I use
move ,03

To put a value in memory after the array and if yes does it mean that the size of the array is totally dependent on me? How does the above instruction mess with the stack? Are pointers just the names given to variables in assembly? That is

num1 db 0, "$"

Is num1 a pointer?

Posted on 2013-01-30 19:20:33 by Snake4eva
Yeah, you could do it like that, but you'd need to tell Nasm the size...

mov byte , 1 ; array [0] = 1
mov byte , 2 ; array [1] = 2

... and yes, you can write past the end of the array - Nasm won't stop you - but you don't want to do it! Note that we start at zero, so is the end of a ten-byte array.

Might be more useful to do something like...

section .bss
    array resb ARRAY_SIZE
section .text
    mov bx, array
    mov al, 1
    mov cx, ARRAY_SIZE
    mov , al
    inc bx
    inc al
    loop top

Now you've got array[0] = 1 through array[9] = 10. (none of these instructions mess with the stack)

I guess num1 is a "pointer" - it's the address (the offset part of the address). "" is the contents (currently 0).


Posted on 2013-01-30 23:17:48 by fbkotler
How would you create a function using the C calling convention and how would you create a class?
Posted on 2013-01-31 10:33:11 by Snake4eva
I wouldn't. 16-bit code? What "model"? 16-bit code has the complication that code and/or data can be "near" or "far" (including segment as well as offset). So your parameters may start at a different part of the stack, and be different sizes... depending...

global myfunc ; or _myfunc...
myfunc: ; or _myfunc
    push bp ; save caller's bp
    mov bp, sp ; set up "stack frame"

    sub sp, 8 ; if you want/need local variables

    push bx ; save registers that C wants preserved
    push si ; only needed if you alter 'em
    push di

; do your thing
    mov ax, ; or 6 - first parameter
    add ax, ; or 8 - second parameter
; return result in ax

    pop di
    pop si
    pop bx ; if we saved 'em

    mov sp, bp ; destroy stack frame
    pop bp
    ret ; or retf

That's untested, and may not be right, but it's the general idea. If your data is "far" it gets even more complicated (have to save and restore ds, too). Have you actually got a 16-bit compiler?

32-bit code is more straightforward - everything's near. There's still the issue of where and if it likes underscores. OpenWatcom C likes "myfunc_"! Nasm has the "--prefix" and "--postfix" options that will take care of it if you write your code without underscores.

64-bit code is a whole 'nother world. I understand the calling conventions differ between Linux and Windows (...and ?). I can't help ya there. (I'm going to be a busy lad when I finally upgrade my hardware!)

What's a class?


Posted on 2013-01-31 14:08:23 by fbkotler
A C++ or high level class eg:
class student
string name;
float gpa;

I would like to know how to high level structures such as data types and classes and functions are implemented.
Posted on 2013-02-22 08:07:59 by Snake4eva