Hello!

To get straight to the point, I can't seem to get division to work. I haven't been programming in Assembly long, and I've been trying to get this to work for a couple of days now with no success.

Anyway, here's my code:

section .text
  
  global _main
  extern _write

  _main:
    mov al, 5h
    mov bl, 2h
    div bl
    xor bh, bh
    mov bl, al
    push 1
    push bx
    push 1
    call _write

    add esp, 12
    mov eax, 0
    ret

It compiles fine, but when I try to run it, all it does is spew out a lot of odd symbols and then crash, any help is greatly appreciated!

Are we supposed to guess what OS you're using, or what _write is supposed to do?

http://linux.die.net/man/2/write
If it's this "write", then the second parameter needs to be a POINTER to some memory, not the munged result of your calculation.
No wonder it crashes.

I'm using Windows 7, I didn't think it was important so long as you knew the architecture.

That does appear to be the _write command I'm using, however. Very odd... I thought I was passing it an address, I was under the impression that using [eax] was like a dereference in C++, and that just eax by itself was the address, like a pointer. I guess I'm wrong?

Finally managed to get it working, I think I might have had it backwards and eax is the value, while [eax] is the address. Or maybe there is no direct analogy between this and C++, either way it's working now. Here's the working code if anyone is interested:

section .data

  var: db 0

section .text
  
  global _main
  extern _write

  _main:
    mov ax, 51
    mov dx, 0
    mov bx, 10
    div bx
    mov [var], al
    add byte[var], 48
    lea eax, [var]
    push 1
    push eax
    push 1
    call _write

    add esp, 12
    mov eax, 0
    ret

Thank you for putting me on the right track Salem!:)
Now I can continue studying.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.