Help (urgent) : Write result to a created file

Started by boon, September 15, 2008, 08:07:01 AM

Previous topic - Next topic

boon

another problem...when i try to pass a value i calculated to an uninitialize identifier, n write to the file i have created, the result just show ? in the file, why is this happen?

buf2 db ?
one db 1
two db 2
...

mov ax,one
add ax,two
mov buf2,ax

boon

anyone please help me solve my problem? i had try many methods but all seem not working, it keep print the "?" but not the value i calculated..

sinsi

You are defining your data as bytes (db), but accessing them as words (ax).
If you want to write "3" to your file you have to convert it (hint: look at the masm32 functions).
Light travels faster than sound, that's why some people seem bright until you hear them.

FORTRANS

Quote from: boon on September 16, 2008, 04:45:04 PM
emm, Steve sorry to tell that, i am totally new to masm, so i have no idea how to use debug.exe, p command all that, where can i find it and how to use it?

On this Windows XP system, I found;


Directory of C:\WINDOWS\system32

08/29/2002  07:00 AM            20,634 debug.exe
               1 File(s)         20,634 bytes


   There are tutorials out on the web.  Or you could go to
Google Groups and search comp.lang.asm.x86 and
alt.lang.asm to see if there is a preferred tutorial.  Running
debug, and typing a question mark gives a command summary.


C:\>debug
-?
assemble     A [address]
compare      C range address
dump         D [range]
enter        E address

    fill         F range list
    go           G [=address] [addresses]
    hex          H value1 value2
    input        I port
    load         L [address] [drive] [firstsector] [number]
    move         M range address
    name         N [pathname] [arglist]
    output       O port byte
    proceed      P [=address] [number]
    quit         Q
    register     R [register]
    search       S range list
    trace        T [=address] [value]
    unassemble   U [range]
    write        W [address] [drive] [firstsector] [number]
    allocate expanded memory        XA
[#pages]
deallocate expanded memory      XD [handle]
map expanded memory pages       XM [Lpage] [Ppage] [handle]
display expanded memory status  XS
-q
C:\>
[/tt]

   The Proceed command steps through the program one
line at a time.

   Basically, you produce a listing of your code so you can
see what opcodes your code produces, and the address
of each opcode.  Then run debug with your program's
name on the command line.  You can then step through
the program and see what happens to the registers.

   An example with code I posted in another thread.  I
start the debugger.
E:\MASM\WORK>debug testtext.com
-


   I can use the U command to look at the code.

152A:0100 8CC8          MOV     AX,CS
152A:0102 8ED8          MOV     DS,AX
152A:0104 B80300        MOV     AX,0003
152A:0107 CD10          INT     10
152A:0109 B800B8        MOV     AX,B800
152A:010C 8EC0          MOV     ES,AX

{snip}

   And then step through using the P command.

-p

AX=152A  BX=0000  CX=0076  DX=0000  SP=FFFE  BP=0000  SI=0000  DI=0000
DS=152A  ES=152A  SS=152A  CS=152A  IP=0102   NV UP EI PL NZ NA PO NC
152A:0102 8ED8          MOV     DS,AX
-p

AX=152A  BX=0000  CX=0076  DX=0000  SP=FFFE  BP=0000  SI=0000  DI=0000
DS=152A  ES=152A  SS=152A  CS=152A  IP=0104   NV UP EI PL NZ NA PO NC
152A:0104 B80300        MOV     AX,0003
-p

AX=0003  BX=0000  CX=0076  DX=0000  SP=FFFE  BP=0000  SI=0000  DI=0000
DS=152A  ES=152A  SS=152A  CS=152A  IP=0107   NV UP EI PL NZ NA PO NC
152A:0107 CD10          INT     10
-


  The first line was MOV AX,CS so the first P executes that and
you can see 152A in AX.  Then DS is updated, though to the same
value it holds.  Then AX is loaded with 3 in preparation for the INT.

   Easy as rhubarb pie?  The simpler commands are fairly easy to use.
Try and locate a tutorial before doing much more than U (unassemble),
P (proceed), D (dump), G (go, which starts running your program),
and of course Q (quit).

HTH,

Steve N.

MichaelW

boon,

As sinsi pointed out, the three instructions should all return:

error A2070: invalid instruction operands

When you try to assemble them because the operands are different sizes (AX is a word, and one, two, and buf2 are defined as bytes).

If you are trying to add the values 1 and 2 to get the value 3, and then write the digit "3" to the file, you will need code to convert a value to a decimal (base 10) or hexadecimal (base 16) digit. To convert the values from 0 to 9 to a decimal digit, you can simply add the ASCII code for 0 (= 48) to the value. For example:
0+48=48, the ASCII code for the digit "0"
1+48=49, the ASCII code for the digit "1"
. . .
9+48=57, the ASCII code for the digit "9"

For values > 9, you will need more complex code to convert the value to a string. This has been discussed many times, try searching the forum for the word decimal. If you use the Advanced search and narrow the search to the 16-bit DOS programming board, you should find some simple examples.








eschew obfuscation

boon

i had define word to all the three identifiers and it works, thanks guys...but when come to convert value to string i really don't have any idea about it..i had seen some examples on the forum but with my kindergarden level of assembly language, i can't understant how is it running..somemore i need to convert floating point to string so that i can write it to my file and it is more complicated than convert decimal to string...God help...getting crazy with assembly language...

sinsi

QuoteThe Proceed command steps through the program one line at a time.
Just a nitpick, you should use Trace to step through one instruction at a time.
If you have "call ...." then Proceed will not trace into that subroutine but call it without tracing.
Good for when your code has "int 21h" - you don't want to trace through that.

boon, converting hex into a string is hard enough, floating-point is harder still.
You're in the 16-bit (DOS) subforum, is there a reason you are sticking to DOS? Win32 is a hell of a lot easier
and there's a lot of code here on the board and in the masm32 package.
Light travels faster than sound, that's why some people seem bright until you hear them.

boon

actually i am taking microprocessor subject now and at first my lecturer ask us to use 16-bit to write a program calculating quadratic equation, he said 16-bits is the basic so start learning from it..and now i am improving my program so that i can save the previous result, but seems there are lots problems...in addition, when i want borrow referrence books from library, every books are teaching 16-bits and none of the books are teaching 32-bit programming..that's why i have to stick with 16-bit dos programming...

FORTRANS

Hi sinsi,

   You are correct.  However since the posted code had INT's
and no CALL's, I thought to keep it simple.  Maybe too simple?
And of course the Dump command for looking at data is useful,
but did not seen relevant then.  But if he is having trouble
saving results?

Regards,

Steve