notes/school/os-sec/uebung/02/02_2.c
Valentin Brandl d5d225e53f
All checks were successful
the build was successful
Add ossec solution
2018-11-12 14:40:59 +01:00

64 lines
1.2 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include<inttypes.h>
/*
PUSH EBP
MOV EBP, ESP
SUB ESP , 4 ; reserve 4 bytes in the stack frame -> local variable int32_t -> i
MOV DWORD PTR [ EBP 4 ] , 1 ; initialize local variable with 1
; EBP+8 : first parameter -> a
; EBP+12 : second parameter -> b
loop:
CMP DWORD PTR [ EPB+ 8 ] , 99 ; while (a >= 99)
JL SHORT exit
LEA EAX, [ EBP+12 ] ; eax = *b;
DEC DWORD PTR [EAX] ; *b--;
CMP DWORD PTR [ EBP+ 12 ] , 99 ; if (b >= 99)
JL SHORT continue
JMP SHORT exit ; break
continue:
MOV EDX, [ EBP+8] ; edx = a
LEA EAX, [ EBP 4] ; eax = *i
ADD DWORD PTR [EAX] , EDX ; *eax += edx -> i += a
INC DWORD PTR [ EBP+8] ; a++;
JMP SHORT loop ; loop
exit:
MOV EAX, DWORD PTR [ EBP 4] ; return i
MOV ESP , EBP ; cleanup
POP EBP ; cleanup
RETN
*/
int32_t f(int32_t a, int32_t b) {
int32_t i = 1;
b--;
while (a >= 99 && b < 99) {
i += a;
a++;
b--;
}
return i;
}
/* int32_t f(int32_t a, int32_t b) { */
/* int32_t i = 1; */
/* while (a >= 99) { */
/* b--; */
/* if (b < 99) { */
/* i += a; */
/* a++; */
/* } else { */
/* break; */
/* } */
/* } */
/* return i; */
/* } */
int main(void) {
f(1,2);
}