Intel IA-32 Assembly

Posted by Kay on Stack Overflow See other posts from Stack Overflow or by Kay
Published on 2010-04-28T10:27:33Z Indexed on 2010/04/28 19:27 UTC
Read the original article Hit count: 310

Filed under:
|
|

I'm having a bit of difficulty converting the following java code into Intel IA-32 Assembly:

 class Person() {
   char name [8];
   int age;

   void printName() {...}

   static void printAdults(Person [] list) {
     for(int k = 0; k < 100; k++){
       if (list[k].age >= 18) {
         list[k].printName();
       }
     }
  }
}

My attempt is:

Person:
    push ebp; save callers ebp
    mov ebp, esp; setup new ebp
    push esi;    esi will hold name
    push ebx;    ebx will hold list
    push ecx;    ecx will hold k

init:
    mov esi, [ebp + 8];
    mov ebx, [ebp + 12];
    mov ecx, 0;    k=0

forloop:
    cmp ecx, 100;
    jge end;    if k>= 100 then break forloop 
    cmp [ebx + 4 * ecx], 18 ;
    jl auxloop;    if list[k].age < 18 then go to auxloop
    jmp printName;

printName:


auxloop:
    inc ecx;
    jmp forloop;

end:
    pop ecx;
    pop ebx;
    pop esi;
    pop ebp;

Is my code correct?

NOTE: I'm not allowed to use global variables.

© Stack Overflow or respective owner

Related posts about assembly

Related posts about intel