×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

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

Code Modification

Code Modification

Code Modification

(OP)
As anyone can see I'm a newbe in assembly. I'm just trying to learn a bit and practicing. My problem right now is that I just created a program that allows me to enter any number from 1 to 5 and once I enter it the program will display the number I entered but instead of a number it will say the word. For example if I enter 5 it will the number you entered is "five". I know how to display it in number but I'm having a hard time trying to display it in words. Any help will be appreciated. My code is the following:

-------begin code---------
.model small
.stack 100h
.data
    
Number      db ?
message1    db "Enter a number from 1 to 5:$ "
message2    db " The word is [$ "
message3    db " Enter another number from 1 to 5:$ "
message4    db " The word is [$ "

.code
main proc
    mov ax,@data
    mov ds,ax

    mov dx,offset message1
    mov ah,9
    int 21h

    mov ah,1
    int 21h
    mov number,al

    mov dx,offset message2
    mov ah,9
    int 21h

    mov ah,2
    mov dl,number
    int 21h
    mov ah,2
    mov dl,']'
    int 21h

    mov dx,offset message3
    mov ah,9
    int 21h
            
    mov ah,1
    int 21h
    mov number,al

    mov dx,offset message2
    mov ah,9
    int 21h

    mov ah,2
    mov dl,number
    int 21h
    mov ah,2
    mov dl,']'
    int 21h
           
    mov ax,4c00h
    int 21h
main endp
end main

--------- end of code ------------

RE: Code Modification

Please use the [code][/code] tags when posting code.

--

RE: Code Modification

As far as i can see the code just displays the number, you haven't made an effort yet to display it in words.

maybe you can make an array of strings which contains the numbers in words.
Next you convert the ASCII character gotten from the user to decimal, and use that as an index into the array.

RE: Code Modification

(OP)
This my modified code but by some reason when I enter the number it writes at the screen all the messages at the same time. For example if I enter 1 it writes:

The number is one
The number is two
The number is three
The number is four
The number is five

What am I doing wrong? Any help will be appreciated.

CODE

.model small
.stack 100h
.data
    
Number     db ?
message    db "Enter a number from 1 to 5: $ "
one        db 0Ah,"The number is one $",0
two        db 0Ah,"The number is two $",0
three      db 0Ah,"The number is three $",0
four       db 0Ah,"The number is four $",0
five       db 0Ah,"The number is five $",0      

.code
main proc
    mov ax,@data
    mov ds,ax
    

    mov dx,offset message
    mov ah,9
    int 21h


    mov ah,1
    int 21h
    mov number,al
       
 
    cmp number,1
    je L1

    cmp number,2
    je L2

    cmp number,3
    je L3

    cmp number,4
    je L4
 
    cmp number,5
    je L5

L1:
    mov dx,offset one
    mov ah,9
    int 21h

L2:
    mov dx,offset two
    mov ah,9
    int 21h

L3:
 
    mov dx,offset three
    mov ah,9
    int 21h

L4:

    mov dx,offset four
    mov ah,9
    int 21h

L5:

    mov dx,offset five
    mov ah,9
    int 21h
           
    mov ax,4c00h
    int 21h

main endp
end main

RE: Code Modification

After printing each message your code drops straight into the next message block.

CODE

L1:
    mov dx,offset one
    mov ah,9
    int 21h
    jmp short alldone
L2:
    mov dx,offset two
    mov ah,9
    int 21h
    jmp short alldone
L3:
 
    mov dx,offset three
    mov ah,9
    int 21h
    jmp short alldone
L4:

    mov dx,offset four
    mov ah,9
    int 21h
    jmp short alldone
L5:

    mov dx,offset five
    mov ah,9
    int 21h
alldone:           
    mov ax,4c00h
    int 21h


Hope this helps.

vampirebat

RE: Code Modification

(OP)
That worked but now instead of appear all the messages. No matter which number I choose it will always answer me "The number is one". =/

RE: Code Modification

this is because there was no match. it drops down to the L1 label, executes the code there and jumps to alldone.

the character you input is ASCII character '1', the values you are checking for are all numeric values,
which have completely different values for the computer "internally".

replace

  cmp number,1

with

  cmp number,'1'

do this with all the other numbers as well, and yer prog should work.

RE: Code Modification

(OP)
Thank You!! It worked!!!!

RE: Code Modification

or

    mov ah,1
    int 21h
    and al, 0fh
    mov number,al

and leave your cmp instructions unchanged

you also need:

    cmp number,5
    je L5
    jmp short alldone

to handle invalid inputs

Hope this helps.

vampirebat

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