1 Replies - 811 Views - Last Post: 18 July 2013 - 11:20 PM

#1 Mbare  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 22
  • Joined: 02-September 12

On macro , edi and esi registers

Posted 04 July 2013 - 08:32 AM

I need some help to fully understand this section of script.
This is a simple script that works with queues, and this is a section of code relative to enqueue; first we see it in C:

/* n is length of queue   */
void enqueue(){
   if (count<n){
      printf("\n%s\n","Error: Queue is full"); 

and in MASM:

enqueue macro
        .if count < lengthof queue
         inc count        ; increment count
         mov eax,number   ; load eax with number
         mov [edi],eax    ; store eax in rear
         mov eax,edi      ; copy edi (rear) to eax
         sub eax,offset queue ; subtract address of queue..HERE WHY????
         add eax,4        ; increment eax by 4
         cdq              ; convert double to quad
         mov ecx,sizeof queue ; get size of queue (bytes)
         idiv ecx         ; divide
         mov edi,offset queue ; load address in rear 
         add edi,edx          ; add remainder to rear
         INVOKE printf, ADDR errfmt, ADDR errmsg2

But I need to know two things:
1)Why in this macro we canít use conditional assembly?? or we can??

2)Whay we need to subtract from eax address of queue, before to add 4 to it??
edi is a pointer to first queue item, because in main we declare :

mov edi,offset queue+0.

Then I do not understand why we subtract queue offset to this address;
would be sufficient incremeant eax by 4, directly????
and again, why we can't do that instead? :

mov eax, 4
add esi, eax ;???? it's possible use add with two registers..right??

i'm a little confused... :crazy:
ps if You need full code , i'll do it..., thanks in advance!

Is This A Good Question/Topic? 0
  • +

Replies To: On macro , edi and esi registers

#2 turboscrew  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 164
  • View blog
  • Posts: 1,058
  • Joined: 03-April 12

Re: On macro , edi and esi registers

Posted 18 July 2013 - 11:20 PM

I hope I understood you right...

1) I guess you are trying to use compile time conditionals for controlling the runtime behaviour.

2) By a quick look, I guess the idea is to get the index to do the wrapping (%)
to it, rather than to the pointer.

This post has been edited by turboscrew: 18 July 2013 - 11:21 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1