Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

need help with assembler

i must make an assemble program that will count some number and then div it with 2.
i wrote the following

start:
mov ah, 0x09 ; keert terug naar dos scherm.
int 0x21 ; resultaat wordt op beeldscherm getoond

mov al, 0x28 ; eerste getal
mov ah, 0x06 ; tweede getal
add eax, al ; zet waarde al in register eax
add eax, ah ; tel waarde register ah op bij eax.

mov al, 0x17 ; derde getal
mov ah, 0x46 ; het vierde getal
add eax, al ; tel waarde al (0x7) op bj eax
add eax, ah ; dit is de som van alle getallen
:loop
; controleer deling door 2
Mov al, 0 ;zet waarde 0 in al
Mov ah, 1 ;ze twaarde 1 in ah
div eax, 2 ; delen de totale som van eax door2,antwoord =eax
Cmp eax, al ; vergelijk waarde eax met al
Je deelbaar ; spring naar deelbaar als rest =0
Cmp eax, ah ; ; vergelijk waarde eax met aH
Je niet_deelbaar ; spring als rest = 1

.data
deelbaar db

Comments

  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    Look at the following code:
    [code]
    xor eax, eax ;Set eax=0
    mov al, 0x01
    mov ah, 0x02
    [/code]
    The contents of AL is 1, AH is 2, and EAX is 2*2^16 + 1.

    You see, al, ah, eax are all part(s) of the same register:
    [code]
    32 bits || 31 ... 16 | 15 14 ... 8 7 ... 1 0 ||
    **-- ah --** **-- al --*
    **-------- ax ---------*
    **------------- eax -------------------**
    [/code]
    This is how to look at it (forgive my ASCII drawing skills... they are somewhat lacking). eax is the full 32 bits register. ax is the low 2 bytes of that register. ah is the high byte of ax. al is the low byte of ax. So ah and al are both part of ax and eax.
    Mofifying the one will modify the other.

    ax, ah, al are all just different entries into the same register.

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • K-LifeK-Life Member Posts: 1
    Hello Richard!
    As i understood, You want to see eax register in bits. You can try transfering containing of eax to mmx for exml. And then look at the FPU. It's very easy if you use c++Builder or Delphi.
    Best regards, Vladimir
  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    : Hello Richard!
    : As i understood, You want to see eax register in bits. You can try
    : transfering containing of eax to mmx for exml. And then look at the
    : FPU. It's very easy if you use c++Builder or Delphi.
    : Best regards, Vladimir
    :

    I think you misunderstood ;) First of all, Richard (that's me) is the one answering the question ;)

    [color=Blue]EDIT:[/color] Or are you the original poster?

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • rickjerickje Member Posts: 2
    i have adjust the script.
    i now have a problem with the div command..
    it is this now.
    mov ah, 0x09
    int 0x21
    xor eax, eax
    add eax, 0x28
    add eax, 0x06
    xor ebx, ebx
    add ebx, eax
    xor eax, eax
    add eax, 0x17
    add eax, 0x46
    add ebx, eax
    controle: ; controleer deling door 2
    xor eax, eax ;zet register eax=0
    Mov Eax, 2 ;zet waarde 0 in al
    Mov ah, 1 ;zet waarde 1 in ah
    div ebx, eax ; delen de totale som van ebx door twee, antwoord is ebx
    Cmp ebx, ax ; vergelijk waarde ebx met al
    Je deelbaar ; spring naar deelbaar als rest =0
    Cmp ax, ah ; ; vergelijk waarde eax met aH
    Je niet_deelbaar ; spring als rest = 1
    .data
    deelbaar db "Som is deelbaar door 2" ,13,10,"s"
    niet_deelbaar db "Som is deelbaar door 2" ,13,10,"s"
    end:
  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    Use of the Div instruction:
    [code]
    [b]div [/b][italic]register[/italic]

    Divides edx:eax by [italic]register[/italic] and stores the result in eax
    [/code]

    That it's this way (edx:eax) can be quite handy when also using multiply, to do something like eax * 54564 / 12789 without getting precision loss caused by first calculating eax * 54564, then rounding, and then dividing. Because:
    [code]
    [b]mul[/b] [italic]register[/italic]

    Multiplies eax by [italic]register[/italic] and stores the result in edx:eax
    [/code]

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
Sign In or Register to comment.