Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main(int argc, char **argv)
- {
- int numbers[10];
- int index = 0;
- char *array_sum = "The total sum of array is: %d";
- char *array_elements = "Numbers - %d\n";
- __asm
- {
- $CHECK_index:
- // Move index value to eax register
- mov ecx, index
- // Check if index >= 10
- cmp ecx, 10
- // Jump to $END_LOOP if true
- jge $END_LOOP
- // Move value of ecx register to array
- mov numbers[TYPE numbers * ecx], ecx
- // Increment the value of index by 1
- inc index
- // Jump to start of check loop
- jmp $CHECK_index
- $END_LOOP:
- // Assign value of 0 to index
- mov index, 0
- // Assign value of 0 to ebx register
- mov ebx, 0
- // Jump to $PRINT_numbers loop
- jmp $PRINT_numbers
- $PRINT_numbers:
- // Move index value to eax register
- mov ecx, index
- // Check if index >= 10
- cmp ecx, 10
- // Jump to $TERMINATE if true
- jge $TERMINATE
- // Move array value into eax register
- mov eax, numbers[TYPE numbers * ecx]
- // Sum the values in the ebx register
- add ebx, eax
- // Push eax to the stack
- push eax
- // Push formatted string to stack
- push array_elements
- // Call printf
- call printf
- // Increment the value of index by 1
- inc index
- // Jump to start of print numbers loop
- jmp $PRINT_numbers
- $TERMINATE:
- // Push ebx to the stack
- push ebx
- // Push formatted string to stack
- push array_sum
- // Call printf
- call printf
- // Clean the stack
- add esp, 16
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement