Conversion of C-pointers to Assembly

Asked

Viewed 230 times

0

Good afternoon, I will have Assembly test and I have a question that is about pointers in Assembly. I’m trying to do an exercise, but I can’t fix it. "Consider the statements in C:

int x=100, y=200;
int far *ptx;
int far *pty;

assuming the instructions have already been executed:

ptx=&x;
pty=(int *)malloc(sizeof(int));

my question is on how to encode the following paragraphs in Assembly:

to) ptx=pty

b)*ptx=*pty

  • "int far *" no longer exists, unless you are programming for MS-DOS...

  • 1

    we use dosbox to program, with turboC

  • use the Debugger to see the Assembly instructions, or in the compilation use the option (which I don’t know what it is) to generate an Assembly listing...I don’t remember the details, but I know the two things above are possible

  • the problem is that this is a test exercise. I’m going to do it frequently and I needed to know this, but I have no way of knowing

  • I have to do that code in writing, not on the computer

  • What architecture are you using? x86 or MIPS?

  • We use 8086 processor Assembly

Show 2 more comments

1 answer

1


Assuming "real mode" programming for 8086, then we will use the general-purpose register AX (16-bit), the general-purpose register and index register BX (16-bit), and the segment register ES (16-bit).
PS. ES = "extra segment"

int x=100, y=200;
int far *ptx;
int far *pty;

assuming the instructions have already been executed:

ptx = &x;
pty = (int *)malloc(sizeof(int));

my question is on how to encode the following paragraphs in Assembly:

isso aqui parece razoavelmente fácil: cada ponteiro far é composto por 2 bytes de
segmento e dois bytes de offset
a) ptx = pty

    ; offset
    MOV AX, word ptr pty
    MOV word ptr ptx, AX

    ; segmento
    MOV AX, word ptr pty+2
    MOV word ptr ptx+2, AX

aqui tem que usar o registrador ES
b) *ptx = *pty 

    ; carrega pty em ES:BX
    LES BX, pty

    ; carrega *pty em AX
    MOV AX, word ptr ES:[BX]

    ; carrega ptx em ES:BX
    LES BX, ptx

    ; salva AX em *ptx
    MOV word ptr ES:[BX], AX

It is possible to have some syntax problem, we would have to run the MASM 17 bits to check this, but overall that’s it.

  • thank you very much for your help

Browser other questions tagged

You are not signed in. Login or sign up in order to post.