Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; typdef struct T_impls {
- NEXT EQU 0 ; struct T_impl *next;
- VALUE EQU 4 ; int value;
- ; } T;
- SECTION .data ; /* contains initialized data */
- SECTION .bss ; /* contains uninitialized data */
- ts RESD 8 ; T ts[4]; /* 4 Mal 2 DWORD Speicherplatz */
- m RESD 1 ; int m;
- SECTION .text ; /* contains code
- GLOBAL _start ;
- _start: ; void main(void){
- nop ; /* do not remove the "nop" */
- mov ebx, ts ; /* Fusspunkt von ts nach ebx */
- mov eax, 12 ;
- mov [ebx+0*8+VALUE], eax ; ts[0].value = 12;
- mov eax, ts+2*8 ;
- mov [ebx+0*8+NEXT], eax ; ts[0].next = &ts[2];
- mov eax, -1 ;
- mov [ebx+1*8+VALUE], eax ; ts[1].value = -1;
- mov eax, ts+0*8 ;
- mov [ebx+1*8+NEXT], eax ; ts[1].next = &ts[0];
- mov eax, 11 ;
- mov [ebx+2*8+VALUE], eax ; ts[2].value = 11;
- mov eax, ts+3*8 ;
- mov [ebx+2*8+NEXT], eax ; ts[2].next = &ts[3];
- mov eax, 17 ;
- mov [ebx+3*8+VALUE], eax ; ts[3].value = 17;
- mov eax, ts+1*8 ;
- mov [ebx+3*8+NEXT], eax ; ts[3].next = &ts[1]
- push DWORD ts+2*8 ;
- call findMax ;
- mov [m], eax ; m = findMax(&ts[2]);
- push DWORD ts+1*8 ;
- call findMax ;
- add [m], eax ; m += findMax(&ts[1]);
- push DWORD ts+3*8 ;
- call findMax ;
- add [m], eax ; m += findMax(&ts[3]);
- push DWORD ts+0*8 ;
- call findMax ;
- add [m], eax ; m += findMax(&ts[0]);
- mov ebx, eax ; return m;
- ; }
- end:mov eax, 1 ; /* the exit system call
- ; no errorcode
- int 80h ; execute system call */
- ; }
- findMax: ; int findMax(T *b) { /* *b in [ebp+8] */
- push ebp ; /* ebp sichern und neueinstellen */
- mov ebp, esp ;
- sub esp, 4 ; /* Speicherplatz für lokale Variablen */
- ; /* *iter in [ebp-4] */
- ; /* ret in eax */
- push ebx ; /* Register sichern */
- push esi ;
- push ecx ;
- mov ecx, [ebp+8] ; /* *iter in ecx */
- mov [ebp-4], ecx ; T *iter = b;
- mov eax, [ecx+VALUE] ; int ret = b->value;
- do: ; do {
- mov ecx, [ecx+NEXT] ; iter = iter->next;
- mov ebx, [ecx+VALUE] ;
- cmp ebx, eax ; if (iter->value > ret) {
- jle ife ;
- mov eax, ebx ; ret = iter->value;
- ife: ;
- cmp ecx, [ebp+8] ;
- jne do ; while (iter != b);
- mov [ebp-4], ecx ; /* iter zurueckschreiben */
- pop ecx ; /* Register rueckstellen */
- pop esi ;
- pop ebx ;
- add esp, 4 ; /* lokale Variable freigeben */
- pop ebp ; /* ebp rueckstellen */
- ret 4 ; /* Parameter freigeben */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement