Author Topic: Help in displaying initialized variable!!!  (Read 6092 times)

MrPimp2

  • Guest
Help in displaying initialized variable!!!
« on: November 10, 2008, 01:18:24 AM »
I have the following code (see below)  My problem is that, whenever I want to DISPLAY the initialized variable "number1", I cannot!! I have tried initializing this variable as a db and as a dd and no luck!  Can any one help?  I DO NOT WANT TO USE THE STACK!

Thanks

lobal main

section .data

number1:    db    4
    ;number1:     dd    4

msg1:         db    "The initialized number is: "
    len1:        equ    $-msg1

enterline:    db    "", 10, 0
    len2:        equ    $-enterline

section .bss

buf1:        resb    4


section .text

main:
    ; Display "The initialized number is: "  message!

mov    eax, 4
    mov    ebx, 1
    mov    ecx, msg1
    mov    edx, len1
    int    0x80

; Display Initialized number "number1"  (HERE IS THE PROBLEM!!!!)


    ;mov    edi, 00000100b

mov    eax, 4
    mov    ebx, 1
    mov    ecx, [number1]
    ;mov    ecx, edi
    int    0x80

; Diplay "enterline", which is simply an empty line!

mov    eax, 4
    mov    ebx, 1
    mov    ecx, enterline
    mov    edx, len2
    int     0x80

mov    eax, 1
    mov    ebx, 0
    int     0x80

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Help in displaying initialized variable!!!
« Reply #1 on: November 10, 2008, 06:31:27 AM »
Without using the stack, eh? Why in the world not??? Well...

lobal main ; [sic]

section .data

number1:    db    4
    ;number1:     dd    4

msg1:         db    "The initialized number is: "
    len1:        equ    $-msg1

enterline:    db    "", 10, 0
    len2:        equ    $-enterline

section .bss

buf1:        resb    4


section .text

main:
    ; Display "The initialized number is: "  message!

mov    eax, 4
    mov    ebx, 1
    mov    ecx, msg1
    mov    edx, len1
    int    0x80

; Display Initialized number "number1"  (HERE IS THE PROBLEM!!!!)


    ;mov    edi, 00000100b

mov    eax, 4
    mov    ebx, 1

add byte [number1], '0'

mov    ecx, number1 ; address!
   ;mov    ecx, edi
mov edx, 1
    int    0x80

; Diplay "enterline", which is simply an empty line!

mov    eax, 4
    mov    ebx, 1
    mov    ecx, enterline
    mov    edx, len2
    int     0x80

mov    eax, 1
    mov    ebx, 0
    int     0x80

That's only good for a single digit. To do multiple digits, look into the "div" instruction. Dividing repeatedly by ten will isolate the digits you need - still need to add '0' to 'em to make ascii characters, and you get 'em in the wrong order. If you were willing to use the stack, you could "just call printf". PITA without using the stack...

Best,
Frank