News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

spot the error assignment

Started by CollegeBoy88, August 09, 2010, 12:53:59 AM

Previous topic - Next topic

CollegeBoy88

first of all, i'd like to thank your for your helpful posts so far, but i need your help again  :wink

there's this piece of code i'd like to share, i'm supposed to spot and explain the error in it

i've marked the instruction which i think would cause an error to occur

just for the record, it's not a homework or project assignment  :wink i won't get any extra credits at college if i solve it. i'm only doing my best to learn assembly.

MOV SI,80H
MOV AL,[SI]
INC SI
XOR AH,AH
ADD SI,AX
MOV BYTE PTR SI,'$'
MOV AH,9
MOV DX,81H
INT 21H
MOV AX,4C00H
INT 21H


here's my solution, correct me if i'm wrong:

the mov byte ptr tells the assembler that i want to load a byte size data into the SI register, right?
i've learned this instruction is used when one wants to load an immediate value into memory by addressing a memory location. for example:

mov byte ptr [bx], 3 ; store the value 3 (8 bits) into the memory location whose address is stored in bx

since storing an immediate data into the SI register (16 bits) automatically extends the value of the immediate data to the size of the destination register, move byte ptr SI, '$' in this case doesn't make sense?

any help would be appreciated. thanks.



redskull

Strange women, lying in ponds, distributing swords, is no basis for a system of government

dedndave

you got the right line, and your soulution is not too far off track
it should be.....
MOV BYTE PTR [SI],'$'

MOV SI,'$' would put the value 24h in the SI register
MOV BYTE PTR [SI],'$' would probably generate an assembly error
you cannot reference the SI register with BYTE PTR (it should generate an error)
[SI] means that the contents of SI is the address of the memory location to be modified
BYTE PTR means the instruction is to modify a byte value at that address (as opposed to a word value)

the purpose of the instruction is to place a "$" DOS string terminator at the end of the command line string
the program will simply echo whatever is on the command line

MichaelW

Assuming that you are assembling with MASM, it will find the problem. But depending on the startup code, there could be another, non-obvious problem.
eschew obfuscation

dedndave

Michael is right   :bg
this might fix it
push es
pop ds

won't be necessary if you are making a .COM program

MichaelW

The problem will be if the program is a .EXE and the startup code sets DS to DGROUP instead of leaving it set to the PSP.
eschew obfuscation

dedndave

ES should hold the PSP segment, even after the startup code

FORTRANS

Hi,

   Two problems in my old version of MASM (after adding
the required junk to keep it happy).  One, the lack of
brackets when accessing memory.  Two, the use of "Word"
style apostrophes.

Steve N.


0128  C6 04 24                 MOV BYTE PTR [SI],'$'
012B  C6 04 00                 MOV BYTE PTR [SI],Æ$Æ
E r r o r   ---        1:Extra characters on line