-2

I can't seem to run my code in emu8086. Can anybody take a look at my code and figure out what's wrong?

org 100h

variable1 db 9h
variable2 db 5
variable3 db 1342h
ret      



mov ax, variable1
mov bl, variable2
mov cx, variable3
  • 2
    What is not working? How do you know? What do you expect to happen? What is happening? Don't go to the doctor and only say "ouch!" – Jens Mar 22 '18 at 08:15
  • I don't even know. Someone just asked me if I know how to debug and see what's wrong with it. I'm not very familiar with assembly so I need your help. If I run the code here's what it says: (5) over 8 bits: 1342h (9) wrong parameters: MOV ax, variable1 (9) operands do not match: 16 bit register and 8 bit address – Janeil Alcano Mar 22 '18 at 08:32

1 Answers1

0

You got these problems in your code:

  1. ret before your code

    ret will return from subroutine so program will not go after this instruction unless stack has been tampered with.

  2. missing start address

    you got org 100h but placed variables there... you code starts after them but you do not have any label to jump to ...

  3. data types mish-mash

    db means 8 bit value and dw means 16 bit value. Some compilers check this if used by 8 bit or 16 bit access... so if you use mov ax,variable1 which is 16 bit <- 8 bit compiler throws an error or warning or whatever.

  4. no background info

    as we do not know what you want to do we can only guess. for example

    mov ax,variable1
    

    means you want to access memory at variable1 like

    mov ax,[cs:variable1]
    

    or just get the offset. Also we do not know your compiler syntax ...

I would change your program to:

    org 100h

    mov ax, variable1
    mov bl, variable2
    mov cx, variable3
    ret      

    variable1 dw 9h
    variable2 db 5
    variable3 dw 1342h

or:

    org 100h

    variable1 dw 9h
    variable2 db 5
    variable3 dw 1342h

start:

    mov ax, variable1
    mov bl, variable2
    mov cx, variable3       
    ret      

the first is used by call 100h and the second by call start. Not sure how labels are defined in your compiler syntax however so the start: line may look a bit different.

Spektre
  • 49,595
  • 11
  • 110
  • 380
  • If I run the code here's what it says: (5) over 8 bits: 1342h (9) wrong parameters: MOV ax, variable1 (9) operands do not match: 16 bit register and 8 bit address. Not very familiar with assembly. – Janeil Alcano Mar 22 '18 at 08:35
  • @JaneilAlcano ow I see you got datasize mish-mash db is 8bit and dw is 16bit .... try now – Spektre Mar 22 '18 at 08:39
  • Ohh thanks a lot! It works now. Just one more question... Is this language still popular and still being used right now or this being replaced by C++? @Spektre – Janeil Alcano Mar 22 '18 at 09:01
  • @JaneilAlcano assembly is low level you can not do huge or complicated things in it effectively but it is still used where speed is important but usually as an inline code for C/C++ (like 99% is C++ and 1% is asm or even less). Majority of programs are being written on higher languages. But once you tap into kernel, drivers and interrupts than sometimes you need asm again ... so it is a good to know it ... – Spektre Mar 22 '18 at 09:37
  • @JaneilAlcano for example take a look at this: [What is the best way to move an object on the screen?](https://stackoverflow.com/a/29579522/2521214) it is a very simple game in asm of mine just look at the source code how unreadable and complicated it is even for very simple game ... and here another one in ancient Turbo C++ [Mouse program in Turbo CPP](https://stackoverflow.com/a/45561564/2521214) which makes a lot more stuff in much less code (also mixed with asm) – Spektre Mar 22 '18 at 09:39