On Wed, 15 Oct 2003 10:57:48pm
  Alexander Horn <[EMAIL PROTECTED]> wrote:

> I just tried out Corewars and came across several problem. Perhaps
> somebody can explain to me what's going on:
> A:   data 5
> B:   data &A
> C:   move Z, [B]
>      data 7
<-- snip -->
> I hope somebody of you knows a logical expl. what me messes me up.

--------------------------------------------

One thing that tends to "mess people up" with assembly language is that
there is no "standard" protocol for listing instructions' arguments.
One language might specify "MOVE <source>, <dest>" while another
might require the notation "MOV <dest>, <source>."

Here's what it the problem looks like in C++ and ASM, compiled with gcc
under Linux for an 80x86 CPU:

(I'm guessing that the last line has the label Z: ...)

--------------------------------------------

% cat example.c++

// pointer example.c++

#include <stdio.h>
int main(void)
{
 int a=5;       //# A : data 5
 int *b=&a;     //# B : data &A  ... location B contains the address of A
 int z=7;       //# Z : data 7

 z = *b;        //# Z = [B]  ... move the content of the location that
                //               B's value points to (i.e., the content
                //               of location A) to location Z.
 printf( "A is %d and Z is %d\n", a, z );
 return 0;

 // P.S.  "Hello, World!"
}

% gcc example.c++
% ./a.out

A is 5 and Z is 5

% gcc -S example.c++

% 80x86 assembly language generated by gcc:^U

% cat example.s

       .file   "example.c++"
       .version        "01.01"
gcc2_compiled.:
.section        .rodata
.LC0:
       .string "A is %d and Z is %d\n"
.text
       .align 4
.globl main
       .type    main,@function
main:
.LFB1:
       pushl %ebp
.LCFI0:
       movl %esp,%ebp
.LCFI1:
       subl $24,%esp
.LCFI2:
       movl $5,-4(%ebp)
       leal -4(%ebp),%eax
       movl %eax,-8(%ebp)
       movl $7,-12(%ebp)
       movl -8(%ebp),%eax
       movl (%eax),%edx
       movl %edx,-12(%ebp)
       addl $-4,%esp
       movl -12(%ebp),%eax
       pushl %eax
       movl -4(%ebp),%eax
       pushl %eax
       pushl $.LC0
.LCFI3:
       call printf
       addl $16,%esp
       xorl %eax,%eax
       jmp .L2
       xorl %eax,%eax
       jmp .L2
       .p2align 4,,7
.L2:
       leave
       ret
.LFE1:
.Lfe1:
       .size    main,.Lfe1-main

.section        .eh_frame,"aw",@progbits
__FRAME_BEGIN__:
       .4byte  .LLCIE1
.LSCIE1:
       .4byte  0x0
       .byte   0x1
       .byte   0x0
       .byte   0x1
       .byte   0x7c
       .byte   0x8
       .byte   0xc
       .byte   0x4
       .byte   0x4
       .byte   0x88
       .byte   0x1
       .align 4
.LECIE1:
       .set    .LLCIE1,.LECIE1-.LSCIE1
       .4byte  .LLFDE1
.LSFDE1:
       .4byte  .LSFDE1-__FRAME_BEGIN__
       .4byte  .LFB1
       .4byte  .LFE1-.LFB1
       .byte   0x4
       .4byte  .LCFI0-.LFB1
       .byte   0xe
       .byte   0x8
       .byte   0x85
       .byte   0x2
       .byte   0x4
       .4byte  .LCFI1-.LCFI0
       .byte   0xd
       .byte   0x5
       .byte   0x4
       .4byte  .LCFI3-.LCFI1
       .byte   0x2e
       .byte   0x10
       .align 4
.LEFDE1:
       .set    .LLFDE1,.LEFDE1-.LSFDE1
       .ident  "GCC: (GNU) 2.95.4 20011002 (Debian prerelease)"



-----------------------------------------------------------------
To get off this list, send email to [EMAIL PROTECTED]
with Subject: unsubscribe
-----------------------------------------------------------------



Reply via email to