Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing output

Status
Not open for further replies.

rounin

Technical User
Joined
Nov 2, 2003
Messages
1
Location
US
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

main:
mov ax, 0
mov [sum], ax

;============================
;loop begins here
;============================
intro:
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
beg:
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

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

smt6:
mov ecx, small
mov edx, slen

e2:
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top