4

I try to write an assembly code that determines if 28 is a perfect number or not. But I have a problem. When I run the code, emu8086 doesn't recognize my labels.
For example in this code:

mov dl,1ch
mov bl,00h ;sum
mov cl,1ch ;counter
dec cl

HERE : mov ax,00h
mov al,dl
div cl ;ax/dl ah=remainder
cmp ah,00h
je SUM ; if ah=0 jump the label SUM 
loop HERE

mov dh,00h
cmp dl,bl
je PERFECT
hlt

SUM :
add bl,cl
jmp HERE   

PERFECT :
mov dh,01
hlt

When loop HERE instruction should run, emu8086 runs the first instruction (mov dl,1ch) of my code. What can I do? What is the problem?

Thanks in advance...

Fifoernik
  • 9,779
  • 1
  • 21
  • 27
Selin Gök
  • 331
  • 1
  • 5
  • 20
  • Beware of this error: `loop HERE` depends on the value in `CX` but you never initialized the upper half of this register! You only wrote `mov cl,1Ch` (the lower half of `CX`) – Sep Roland Jan 08 '17 at 20:40

1 Answers1

8

Remove the blank space between the label name and the colon :

     space
       ▼
PERFECT :

It should be :

    no space
       ▼
PERFECT:
  • 4
    I wonder why emu8086 behaves like that. Why does adding a space before the colon cause it to emit different code? – Wayne Conrad Dec 22 '16 at 19:20
  • 1
    @WayneConrad: emu8086 has a reputation for failing to reject bad input. I haven't used it, just seen questions where it assembled totally bogus code (like `mov al, bx` or something, IIRC from a recent SO question that the OP claimed assembled). I'm guessing that `HERE :` breaks its symbol table or something so it assembles the branch to it as going to the first byte of the segment. That makes this actually a good question, since the OP seems to have used the debugger to see where it actually branches at run-time. I assume emu8086 failed to even warn about a syntax error. – Peter Cordes Dec 23 '16 at 05:19