Intel Assembly Programming
        Posted  
        
            by Kay
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Kay
        
        
        
        Published on 2010-04-29T22:33:14Z
        Indexed on 
            2010/04/29
            22:37 UTC
        
        
        Read the original article
        Hit count: 399
        
class MyString{
char buf[100];
int len;
boolean append(MyString str){
int k;
if(this.len + str.len>100){
for(k=0; k<str.len; k++){
  this.buf[this.len] = str.buf[k];
  this.len ++;
}
 return false;
}
return true;
}
}
Does the above translate to:
start:
  push ebp  ; save calling  ebp
  mov ebp, esp  ; setup new ebp
  push esi  ;  
  push ebx  ;  
  mov esi, [ebp + 8]  ;  esi = 'this'
  mov ebx, [ebp + 14]  ;  ebx = str
  mov ecx, 0  ; k=0
  mov edx, [esi + 200] ;  edx = this.len
append:
  cmp edx + [ebx + 200], 100  
  jle ret_true  ; if (this.len + str.len)<= 100 then ret_true
  cmp ecx, edx
  jge ret_false  ; if k >= str.len then ret_false
  mov [esi + edx], [ebx + 2*ecx]  ; this.buf[this.len] = str.buf[k]
  inc edx  ;  this.len++
aux:
  inc ecx  ; k++
  jmp append
ret_true:
  pop ebx  ; restore ebx
  pop esi  ; restore esi
  pop ebp  ; restore ebp
  ret true
ret_false:
  pop ebx  ; restore ebx
  pop esi  ; restore esi
  pop ebp  ; restore ebp
  ret false
My greatest difficulty here is figuring out what to push onto the stack and the math for pointers.
NOTE: I'm not allowed to use global variables and i must assume 32-bit ints, 16-bit chars and 8-bit booleans.
© Stack Overflow or respective owner