Can someone tell me why my code won't run?

I am new to this guys so sorry for being the newbie on the block.

When I run this program all I get is garbage to print on the screen.

Here is my code:

Start:
mov AX,19H
add AX,32H
mov DX,AX
mov AH,09
int 21h
mov AH,4ch
mov AL,00
int 21h

All it is ment to do is add 25 to 50 and display the total. It doesn't work. I'm using NASM and ALINK.

Comments

  • : I am new to this guys so sorry for being the newbie on the block.
    :
    : When I run this program all I get is garbage to print on the screen.
    :
    : Here is my code:
    : [code]
    : ; --- Start:
    : mov AX,19H
    : add AX,32H
    : mov DX,AX
    : mov AH,09
    : int 21h
    : mov AH,4ch
    : mov AL,00
    : int 21h
    : [/code]

    : All it is ment to do is add 25 to 50 and display the total. It doesn't work. I'm using NASM and ALINK.
    :
    [blue]The function AH=9 of INT 21H will output a text string, and you are passing the numbers in DX. DX should contain the address of a string which should be located in DATA segment. What you need to do is:

    1. Add the values as you did already
    2. Convert the sum into a string terminated by a sign '$'
    3. Point DX to the beginning of that string and call AH=9 function

    Some conversion sample code can be found at my site:
    www.codexxi.com -> Components

    Or search the web on how to convert the value in register into the string value. Basically, the idea is to divide a number by 10 and get the remainders of this division as single digits:

    8468 / 10 -> 846 and 8 remains, so you have now digit '8'
    846 / 10 -> 84 and 6 remains, so you have now digit '6'
    84 / 10 -> 8 and 4 remains, so you have now digit '4'
    8 / 10 -> 0 and 8 remains, so you have now digit '8'

    As soon as result is zero you stop converting.
    The trick is to save digits from the end of a string - you notice that the digits comes out backwards.
    [/blue]
  • : : I am new to this guys so sorry for being the newbie on the block.
    : :
    : : When I run this program all I get is garbage to print on the screen.
    : :
    : : Here is my code:
    : : [code]
    : : ; --- Start:
    : : mov AX,19H
    : : add AX,32H
    : : mov DX,AX
    : : mov AH,09
    : : int 21h
    : : mov AH,4ch
    : : mov AL,00
    : : int 21h
    : : [/code]
    :
    : : All it is ment to do is add 25 to 50 and display the total. It doesn't work. I'm using NASM and ALINK.
    : :
    : [blue]The function AH=9 of INT 21H will output a text string, and you are passing the numbers in DX. DX should contain the address of a string which should be located in DATA segment. What you need to do is:
    :
    : 1. Add the values as you did already
    : 2. Convert the sum into a string terminated by a sign '$'
    : 3. Point DX to the beginning of that string and call AH=9 function
    :
    : Some conversion sample code can be found at my site:
    : www.codexxi.com -> Components
    :
    : Or search the web on how to convert the value in register into the string value. Basically, the idea is to divide a number by 10 and get the remainders of this division as single digits:
    :
    : 8468 / 10 -> 846 and 8 remains, so you have now digit '8'
    : 846 / 10 -> 84 and 6 remains, so you have now digit '6'
    : 84 / 10 -> 8 and 4 remains, so you have now digit '4'
    : 8 / 10 -> 0 and 8 remains, so you have now digit '8'
    :
    : As soon as result is zero you stop converting.
    : The trick is to save digits from the end of a string - you notice that the digits comes out backwards.
    : [/blue]
    :
    Hmmm... Thanks for the reply sir. I still don't know why it can't be as simple as displaying the value in the DX register, or any register. All this convertion stuff is making my brain hurt. I went to your site but most of that code I'm still trying to understand. Isn't there a simply "plug and play" code in a library that displays values in a register?
  • Isn't there a simply "plug and play" code in a library that displays values in a register?

    [green]
    Include procedures for Nasm are prechecked code snipits that you include & use in your program.
    Assembly is nice in the fact that you have full control, but that means that you have to do all the little nitti gritti's, but if you save them in include procedures that are commented, you can use, alter, & understand them at will.
    Librarys don't allow you to see & alter the code within so you never know what you are actually doing.
    I've disassembled pro code and found that a big process was done to get
    a value in DX then the next line was MOV DX,45h
    Which means they used a library.
    I'm a Nasm nut and have made an include WritDigit.inc proc that will do what you want. It's in C:NASMINC16WRITDIGIT.INC
    http://bitdog.home.att.net/files/nasmenv.zip
    it's about a meg in size and has lots of Nasm include proc's & macros
    you can mess with off line. No 5 minutes of clicking to do a 2 second down load of a 1k file, 500 times to get a meg of download like the high IQ sites put ya through. (5x500= 41 hours per meg)
    AND you can do anything you want to with my code.
    Take my name out and put yers in, is good with me.
    Bitdog
    [/green]

  • : Isn't there a simply "plug and play" code in a library that displays values in a register?
    :
    : [green]
    : Include procedures for Nasm are prechecked code snipits that you include & use in your program.
    : Assembly is nice in the fact that you have full control, but that means that you have to do all the little nitti gritti's, but if you save them in include procedures that are commented, you can use, alter, & understand them at will.
    : Librarys don't allow you to see & alter the code within so you never know what you are actually doing.
    : I've disassembled pro code and found that a big process was done to get
    : a value in DX then the next line was MOV DX,45h
    : Which means they used a library.
    : I'm a Nasm nut and have made an include WritDigit.inc proc that will do what you want. It's in C:NASMINC16WRITDIGIT.INC
    : http://bitdog.home.att.net/files/nasmenv.zip
    : it's about a meg in size and has lots of Nasm include proc's & macros
    : you can mess with off line. No 5 minutes of clicking to do a 2 second down load of a 1k file, 500 times to get a meg of download like the high IQ sites put ya through. (5x500= 41 hours per meg)
    : AND you can do anything you want to with my code.
    : Take my name out and put yers in, is good with me.
    : Bitdog
    : [/green]
    :
    :
    I tried the WRITDIGT.INC code but it still prints out when I run it as a bunch of symbols and then stuff other stuff which seems to be a mismatch of words and such. I'll try to type some of it below:

    [blue]!! e =!PSQR1 =!ZY[XHL=!PATH=C:WINDOWSsystem32;C:WINDOWSSystem32Wbem PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.JS;.JSE;.WSF;.WSH PROCESSOR_ARCHITECTURE=x86 PROCERSSOR_IDENTIFIER=x86 Family 6 Model 7 Stepping 1, AuthenticAMD PROCESSOR_LEVEL=6 PROCESSOR_REVISION=x86 PROCESSOR_REVISION=0701 PROGRAMFILES=C:PROGRA~1 PROMPT=2340 Press any key to continuie...[/blue]
  • : : Isn't there a simply "plug and play" code in a library that displays values in a register?
    : :
    : : [green]
    : : Include procedures for Nasm are prechecked code snipits that you include & use in your program.
    : : Assembly is nice in the fact that you have full control, but that means that you have to do all the little nitti gritti's, but if you save them in include procedures that are commented, you can use, alter, & understand them at will.
    : : Librarys don't allow you to see & alter the code within so you never know what you are actually doing.
    : : I've disassembled pro code and found that a big process was done to get
    : : a value in DX then the next line was MOV DX,45h
    : : Which means they used a library.
    : : I'm a Nasm nut and have made an include WritDigit.inc proc that will do what you want. It's in C:NASMINC16WRITDIGIT.INC
    : : http://bitdog.home.att.net/files/nasmenv.zip
    : : it's about a meg in size and has lots of Nasm include proc's & macros
    : : you can mess with off line. No 5 minutes of clicking to do a 2 second down load of a 1k file, 500 times to get a meg of download like the high IQ sites put ya through. (5x500= 41 hours per meg)
    : : AND you can do anything you want to with my code.
    : : Take my name out and put yers in, is good with me.
    : : Bitdog
    : : [/green]
    : :
    : :
    : I tried the WRITDIGT.INC code but it still prints out when I run it as a bunch of symbols and then stuff other stuff which seems to be a mismatch of words and such. I'll try to type some of it below:
    :
    : [blue]!! e =!PSQR1 =!ZY[XHL=!PATH=C:WINDOWSsystem32;C:WINDOWSSystem32Wbem PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.JS;.JSE;.WSF;.WSH PROCESSOR_ARCHITECTURE=x86 PROCERSSOR_IDENTIFIER=x86 Family 6 Model 7 Stepping 1, AuthenticAMD PROCESSOR_LEVEL=6 PROCESSOR_REVISION=x86 PROCESSOR_REVISION=0701 PROGRAMFILES=C:PROGRA~1 PROMPT=2340 Press any key to continuie...[/blue]
    :
    IT WORKS!!! WOOOOOOHOOOOOOO!!!!!!!! THANKS MAN!! YOU ROCK!! I figured out what I did, LOL. I forgot I was trying to call DX to the screen still and when it hit WRITDIGT: DX was getting cleared. LOL. So anyway, it works now. Thanks guys for your help.
  • [green]
    OK, yer up an running now.
    Hay, there are other proc's that print in HEX, BINARY, etc
    then some print to memory an ASCII number, or read from memory
    an ASCII number and return it's value in AX, AL, or EAX.
    Read a command line input ASCII number & return it's value.
    Anyway, there are about 15 of them in C:NASMINC16 check em out.
    Most of them that Write are at the end of the alph organized directory and start with a 'w', the ones that read (Get) start with a G.
    Their input/output is listed at the top of each one
    and that must be satisfied before the do as they claim.
    If you want C type proc's, make a C header & footer macro & use the macro at the top & bottom of each one. (check that it works, of course)
    If you want 32 bit win proc's, add an E on the front of each register.
    Alter AX to EAX and you've got it. The 286 code ideas in each proc works the same in 32 bit code.
    I hope to have a new version of NASMENV.ZIP out in a month or so.

    Anyway, best wishes,
    Bitdog
    [/green]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories