Ok i have a small assembly question


 
Thread Tools Search this Thread
Top Forums Programming Ok i have a small assembly question
# 1  
Old 05-08-2012
Ok i have a small assembly question

I have this small program that runs with the flat assembler. My problem is that at the receive line function it receives the line and if there isn't a $ typed at the end of the user input the program displays a lot of strange stuff, sometimes beeps and then it seems to terminate without causing any damage to m computer. My question is how do I receive a string of characters with assembly maybe with that function without requiring that the user type $ at the end of his/her input.

Code:
ORG 100h ; Start at 100h memory DOS 16 bit .com files
;USE16    ; Use 16 bit mode.
        ; Print line function $ is new line
        ; ah says print line dx is the line to print

        mov ah, 00001001b
        mov dx, msg
        ; Jump to Display It
        jmp DisplayHelloWorld!

DisplayHelloWorld!:
        int 21h

        ; Receive line function
        mov ah, 3fh
        mov dx, Receive
        mov cx, 30
        mov bx, 0
        int 21h

        ; Compare 10d with the value of ah
        cmp dx, Receive
        ; Jump if equal
        je PrintName
        ; Jump if not equal
        jne UnderstandAssembly

UnderstandAssembly:
        ; Call to 21h, again prints line Name
        mov ah, 09h
        mov dx, und
        int 21h

PrintName:
        ; Call to 21h, again prints line Name
        mov ah, 09h
        mov dx, Receive
        int 21h

        ; Tell program to stay alive
        mov ah, 01h
        int 21h
        ; Exit program
        mov ah, 4ch
        int 21h

msg db 'Enter Name: ', '$' ; 0Ah is new line feed, '$' is end of line
und db 'Dx changed before cmp dx, Receive' , '$'
Receive db 30d

# 2  
Old 05-08-2012
The $ sign is the end of string marker and tells the DOS print routine when to stop...that is the reason why you hear bells and whistles or see funky characters on your screen as the DOS print routine is trying its best to make sense of the extended ascii character set which it cant handle...to prevent this from happening change the code so that the user supplied input is concatenated with a $ sign...this way the user doesnt have to type it and clears out all the other issues.
This User Gave Thanks to shamrock For This Post:
# 3  
Old 05-09-2012
alright could you show me how to concatenate '$' to dx before I print Receive. Here's a cleaner version of the program. Line number eighteen is the line that needs concatenating.
Code:
ORG 100h ; Start at 100h memory DOS 16 bit .com files
USE16    ; Use 16 bit mode.
        ; Print line function $ is new line
        ; ah says print line dx is the line to print
        mov ah, 00001001b ; 09h
        mov dx, msg
        int 21h

        ; Receive line function
        mov ah, 3fh
        mov dx, Receive
        mov cx, 1Eh       ; 30d
        mov bx, 0h
        int 21h

        ; Call to 21h, again prints line Name
        mov ah, 09h
        mov dx, Receive
        int 21h

        ; Receive one character to STDIN stored in AL
        mov ah, 01h
        int 21h

PrintFiveCharacters:
        ; Write one character to STDOUT
        mov ah, 02h
        mov dl, al
        int 21h
        add cx, 1d
        cmp cx, 4d
        je PrintFiveCharacters

        ; Tell program to stay alive
        mov ah, 01h
        int 21h
        ; Exit program
        mov ah, 4ch
        int 21h

msg db 'Enter Name: ', '$' ; 0Ah is new line feed, '$' is end of line
Receive db 30d

# 4  
Old 05-09-2012
Can you highlight what is line no 18...and is "Receive" a buffer...if so you could give it an initial fill value so you wouldnt have to catenate.
# 5  
Old 05-10-2012
Here's receive it's kind of like the line right before it accept it defines a line that is 30 bytes long and everything else is truncated.
Code:
Receive db 30d

Here's line 18 This code sends a string to a file which if 0 I believe sends the string to stdout. I want to concatenate dx and '$', '$' being the string I want to add to the end of dx which should be Receive at this point
Code:
        ; Call to 21h, again prints the line
        mov ah, 09h
        mov dx, Receive
        int 21h

And here's a highlight about line 18. dx is the line int 21h will print if you mov ah, 09h and don't change ah. And it actually is a stupid line because receive was already moved into dx right before it. click the image for a list of interrupt options for 21h.
Code:
DOS INT 21h - DOS Function Codes
ImageAH = 09h - WRITE STRING TO STANDARD OUTPUT
  Entry: DS:DX -> '$'-terminated string
  Return: AL = 24h
  Notes: ^C/^Break are checked
  SeeAlso: AH=02h,AH=06h"OUTPUT"

---------- Post updated at 11:21 PM ---------- Previous update was at 11:20 PM ----------

I just want to strcat(dx, '$') right before int 21h/line 19
# 6  
Old 05-10-2012
Quote:
Originally Posted by Errigour
Here's receive it's kind of like the line right before it accept it defines a line that is 30 bytes long and everything else is truncated.
Code:
Receive db 30d

Are you sure about this...because to me it reads that "Receive" is a label for a single byte that holds the decimal number 30. If you need "Receive" to be a 30 byte buffer then you need to do something like...
Code:
Receive db 30 dup('$')

Quote:
Originally Posted by Errigour
Here's line 18 This code sends a string to a file which if 0 I believe sends the string to stdout. I want to concatenate dx and '$', '$' being the string I want to add to the end of dx which should be Receive at this point[/code]
Either catenate a $ sign to the end of Receive or give it an initial fill value...but you cant suffix a $ to the end of dx as it contains the address of the Receive label.
Quote:
Originally Posted by Errigour
Code:
        ; Call to 21h, again prints the line
        mov ah, 09h
        mov dx, Receive
        int 21h

And here's a highlight about line 18. dx is the line int 21h will print if you mov ah, 09h and don't change ah. And it actually is a stupid line because receive was already moved into dx right before it. click the image for a list of interrupt options for 21h.
Yes moving "Receive" to dx is somewhat redundant...but it is better to be safe than sorry.
# 7  
Old 05-10-2012
Quote:
Are you sure about this...because to me it reads that "Receive" is a label for a single byte that holds the decimal number 30. If you need "Receive" to be a 30 byte buffer then you need to do something like...

Code:
Receive db 30 dup('$')
Is there a lower level way to add '$' to the end of receive?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Sparc Assembly

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I am having a hard time with this assignement i cant get the pfib value to print out the fib sequence. ... (1 Reply)
Discussion started by: kenjiro310
1 Replies

2. Programming

vga assembly question

Im trying to make a vga program for linux Im wondering if anyone knows of a simple document on the subject or if someone could show me some basics. What system calls should I use what parameters should I give them. How do I draw a line of pixels green after in vga mode. I prefer nasm but I can use... (2 Replies)
Discussion started by: Errigour
2 Replies

3. Shell Programming and Scripting

Small fast question

just to confirm du from sh show sizes as multiples of 512 byte right? (4 Replies)
Discussion started by: Nick1097
4 Replies

4. Programming

A small question about fork()

Hello experts, I am using fork() in my code but I am confused which output comes first child or parent? I did the following code .My book shows parent first but my linux shows child first.Can anyone tell me why? #include <stdio.h> int main(){ int pid; printf("I am original process with pid... (5 Replies)
Discussion started by: mlhazan
5 Replies

5. Programming

A small question about file descriptor

Can any body tell me when I put close(2), why the code does not show any out put? #include <stdio.h> #include <fcntl.h> #include <errno.h> int main(){ int fd1,fd2,fd3,fd4; close(2); fd1=open("test1.txt",O_WRONLY |O_CREAT | O_TRUNC,0744); fprintf(stderr,"fd1 = %d\n",fd1); ... (5 Replies)
Discussion started by: mlhazan
5 Replies

6. UNIX for Dummies Questions & Answers

Small question regarding SSH

I am looking for some model like this: My Computer ------------- Intermediate Server (IS) ------------- Own Server I must be able to ssh into the Intermediate Internet Server which is generally an online version of SSH service through which I will connect to Own Server. I was the IS to... (2 Replies)
Discussion started by: Legend986
2 Replies

7. Shell Programming and Scripting

A small minix question

First af all hi. i want to create a batch script which inform when users log in last time on system or if they are online when they logged in. I want ot use a file .users which has the usernames of users. i want to print for example peter is ONLINE: Logged in on Wed Feb 11 07:47 alex... (2 Replies)
Discussion started by: sasa
2 Replies

8. Shell Programming and Scripting

small question regarding substr()

Hello.. I am doing some awk-ing and among all I use substr inside it.. I have: ....substr($0,60,37) meaning as U all know take from 37 char. from point 60.. can I put it like this substr($0,60,end of line) meaning take it from point 60 and take all characketrs in that line until line... (2 Replies)
Discussion started by: amon
2 Replies

9. Shell Programming and Scripting

small question of echo | grep command

Hi, i've got the following: a=`echo $b | grep '^.*/'` i'm storing in the variable the value of the variable b only if it has a / somewhere. It works, but i don't want to print the value. How do i give the value of b to the grep command without the echo? thanks! (5 Replies)
Discussion started by: kfad
5 Replies

10. Shell Programming and Scripting

small question

Hi there, I found the following script on the net, i like to use it as a standard template for new scripts. But i do not understand the meaning of the last line, can anybody explain what going on on the last line vflag=off filename= while getopts vf: opt do case "$opt" in v)... (9 Replies)
Discussion started by: janr
9 Replies
Login or Register to Ask a Question