Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Printing output

Printing output

Printing output

First let me say, I'm very, very, (very) new at Assembly.  I'm using NASM on Linux.  I have an undeclared variable that I'm putting numbers I'm getting from user input.  

When I try to output the numbers, I'm not getting anything.  I'm not sure what I'm doing wrong.  Could anyone help me with this?

I realize I still need to work on getting the input down, but for now, I'd be happy to get it to print what I want and that is primarily the values I've inputted into the variable "sum".  

section .data                            ; DECLARED VARIABLES

big        db    "bigger than 50", 0xA
blen     equ    $ - big                              ; length of string "big"
small    db    "smaller than 51", 0xA
slen        equ    $ - small                         ; length of string "small"
greet    db    "Enter any two digit number", 0xA
glen        equ    $ - greet                         ; length of string "greet"

section .bss                            ; UNDECLARED VARIABLES

chr       resw     2              ; reserve uninitialized data
sum     resw     2              ; reserve for a converted number
num     resw     1              ; reserve for a converted number

section .text                            ; CODE TEXT

global main

    mov        ax, 0
    mov        [sum], ax

         ;loop begins here
    mov     eax, 4               ; system call number (sys_write)
    mov     ebx, 1               ; first argument:    file handle (stdout)
    mov     ecx, greet        ; second argument:   pointer to num
    mov     edx, glen         ; third argument:  length of string
    int 0x80
    mov        eax, 3        ; system call number (sys_read)
    mov        ebx, 0        ; first argument: file handle (stdin)
    mov        ecx, chr        ; second argument: pointer to character
    mov        edx, 2        ; third argument: length
    int     0x80            ; call kernel

    cmp        byte [chr], 0x30
    jb    e1                ; char < '0', so get out
    cmp        byte [chr], 0x39
    ja    e1            ;mov    ecx, sum
    ;mov    edx, 5    ; char > '9', so get out

    mov     ax, [sum]
    imul    ax, 10
    mov        bx, 0
    mov        bl, [chr]
    sub        bl, 0x30
    add        ax, bx
    mov        [sum], ax
    jmp    beg

    cmp        word [sum], 50
    jb    smt6            ; smaller than 6
    mov        ecx, big
    mov        edx, blen
    jmp    e2

    mov        ecx, small
    mov        edx, slen

    mov        eax, 4        ; system call number (sys_write)
    mov        ebx, 1        ; first
    int     0x80            ; call kernel

    mov        eax, 4        ; system call number (sys_write)
    mov        ebx, 1        ; first
    mov    ecx, sum
    ;mov    edx, 1
    int     0x80            ; call kernel

    mov    eax, 1            ; system call number (sys_exit)
    mov    ebx, 0            ; exit number
    int     0x80            ; call kernel

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close