Howdy, Stranger!

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

Categories

Help with code

ami_666ami_666 Member Posts: 20
Hi,

I have got this code working, but how can I find that it's giving me the right answer. I have tried like doing arithmetic on paper but I get different answer and gdb debugger gives me different answer. So if some one could help me than that would be great, I will really appreciate it.

Okay, the code is:

.text
.globl main

main: pushl %ebp #save caller's base pointer
movl %esp, %ebp #establish our base pointer

movb $0xff, %al
movb $0xff, %dl
movb $0x12, %al
movb $0x34, %dl
addb %al, %dl

movb $0xff, %al
movb $0xff, %dl
movb $0x72, %al
movb $0x68, %dl
subb %al, %dl

movb $0xff, %ah
movb $0xff, %dh
movb $0xee, %ah
movb $0xdd, %dh
addb %ah, %dh

movb $0xff, %ah
movb $0xff, %dh
movb $0x85, %ah
movb $0x87, %dh
subb %ah, %dh

movl $0xffff, %eax
movl $0xffff, %edx
movl $0x1234, %eax
movl $0x3456, %edx
addl %eax, %edx

movl $0, %eax #return 0 to caller
movl %ebp, %esp #restore stack pointer
popl %ebp #restore caller's base pointer
ret #back to caller

Please if somebody could like work this out on debugger and than tell me about my answer than please reply soon.

Thank you,

Ami

Comments

  • shaolin007shaolin007 Member Posts: 1,018
    [b][red]This message was edited by shaolin007 at 2004-9-30 5:34:14[/red][/b][hr]
    : Hi,
    :
    : I have got this code working, but how can I find that it's giving me the right answer. I have tried like doing arithmetic on paper but I get different answer and gdb debugger gives me different answer. So if some one could help me than that would be great, I will really appreciate it.
    :
    : Okay, the code is:
    [code]
    : .text
    : .globl main
    :
    : main: pushl %ebp #save caller's base pointer
    : movl %esp, %ebp #establish our base pointer
    :
    : movb $0xff, %al
    : movb $0xff, %dl
    : movb $0x12, %al[red]<---???. Why did you put ffh in al if your going to replace it with 12h?[/red]
    : movb $0x34, %dl
    : addb %al, %dl
    :
    : movb $0xff, %al
    : movb $0xff, %dl
    : movb $0x72, %al
    : movb $0x68, %dl
    : subb %al, %dl
    :
    : movb $0xff, %ah
    : movb $0xff, %dh
    : movb $0xee, %ah
    : movb $0xdd, %dh
    : addb %ah, %dh
    :
    : movb $0xff, %ah
    : movb $0xff, %dh
    : movb $0x85, %ah
    : movb $0x87, %dh
    : subb %ah, %dh
    :
    : movl $0xffff, %eax
    : movl $0xffff, %edx
    : movl $0x1234, %eax
    : movl $0x3456, %edx
    : addl %eax, %edx
    :
    : movl $0, %eax #return 0 to caller
    : movl %ebp, %esp #restore stack pointer
    : popl %ebp #restore caller's base pointer
    : ret #back to caller
    [/code]
    : Please if somebody could like work this out on debugger and than tell me about my answer than please reply soon.
    :
    : Thank you,
    :
    : Ami
    :
    [green] Your putting values into a register only to replace it in the following line. What are you trying to accomplush?[/green]


  • ami_666ami_666 Member Posts: 20
    Hi,

    What I am trying to do is:
    0x12 + 0x34 and the answer is going to be stored in al register.
    0x72 - 0x68 and " " " " ...
    0xee + 0xdd and ...
    and so on.
    And I have also assigned different registers like dl, ah, and dh to store 16-bits and 32-bits problems.

    So I am looking for my answer in gdb debugger, but I don't get it, so if you can run my program and then tell me about my mistake than, that would be awesome.

    Thanks,
    Ami
  • shaolin007shaolin007 Member Posts: 1,018
    : Hi,
    :
    : What I am trying to do is:
    : 0x12 + 0x34 and the answer is going to be stored in al register.
    : 0x72 - 0x68 and " " " " ...
    : 0xee + 0xdd and ...
    : and so on.
    : And I have also assigned different registers like dl, ah, and dh to store 16-bits and 32-bits problems.
    :
    : So I am looking for my answer in gdb debugger, but I don't get it, so if you can run my program and then tell me about my mistake than, that would be awesome.
    :
    : Thanks,
    : Ami

    First off you can't fit 32bits or even 16bits into a 8bit register, it's impossible unfortunately! ;-)

    Ok you have it mostly right in your program, but for one thing. You put a value in register and then turn around and put a different value into it without using the 1st one.

    For example:
    [code]
    mov al, ffh[red] al contains ffh[/red]
    mov al, 23h[red] al now contains 23h and not ffh. Waste of code![/red]
    [/code]
Sign In or Register to comment.