-1

I have written an ASM program to try to teach myself ASM. It doesn't seem to be working in emu8086, and I have absolutely no idea why.

org 100h    

mov dx, 05
cld
while:
   int 21h
   cmp dx, 1
   jz outt
   dec dx

   mov ah, 09h
   int 21h

   jmp while
outt:
   mov ah, 4ch
   mov al, 00
   int 21h

   ret
2
  • 2
    "doesn't seem to be working". Could you tell us what you expected, what happened, and what you tried in order to figure out what the problem was? May 18, 2013 at 13:24
  • try adding mov ah, 01h below while: and before int 21h. The doc. May 18, 2013 at 13:43

2 Answers 2

3

The bleak world of Assembler is no place for the uninitiated to venture without a guide...

Your atlas is the Great Tome of Ralf - most importantly, Chapter 21H.

The first thing you are doing is setting DX to 5. Why you'd want to do this is unknown, since you haven't commented your action.

Then you are clearing the direction flag with a CLD. Very sensible - ensures that the auto-adjustment of registers in string instructions proceeds in the logical UP direction.

Your next action is puzzling. When you execute an INT 21H you're asking the OS to do something. If you refer to your atlas, you'll find that the operation to be executed depends on the value in AH. Currently, that's probably 0, since you've not explicitly set it in your program. Hence, if you visit Verse 00 of Chapter 21H of the Tome of Ralf you may just find out why your program appears to terminate without having actually appeared to have done anything.

If you indeed shun that particular instruction, as others have advised, you would observe that your next steps are to

  • Compare DX to 1
  • Probably find unequal, so don't jump
  • Decrement the value of DX by 1
  • Assign 09 to AH

Now we have the magic mantra to ask the OS to do something again - but what? Still got your atlas? Perhaps Verse 09 may help out. Be aware that the value in DX may be intimately involved here.

Having done that, the last few steps are repeated until DX=1, at which point we jump to OUTT.

Again we load AH with what may be a magic value - and AL, too. Want to look into the atlas to find out what it should do?

0

or try removing the first int 21h

If that doesn't work try putting 44 in dx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.