Created
February 16, 2012 01:00
-
-
Save ChrisMoney/0e8d8eb122d725fb1e61 to your computer and use it in GitHub Desktop.
Assembly - Program finds the maximum number of an abstract data set
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Counting Program | |
| #Purpose: This program finds the maximum number of set of data items. | |
| #VARIABLES: The registers have the following uses: | |
| # %edi - Holds the index of the data item being examined | |
| # %ebx = Largest data item found | |
| # %eax - Current data item | |
| #The following memory locations are used: | |
| # data_items - contains the item data. A 0 is used to terminate the data. | |
| .section .data | |
| data_items: | |
| .long 3,67,34,222,45,54,34,45,75,44,33,22,11,66,0 | |
| .section .text | |
| .globl _start | |
| _start: | |
| movl $0, %edi # move 0 into the index register | |
| mov1 data_items(, %edi, 4), %eax #load the first byte of data | |
| mov1 %eax, %ebx #since tis is the first item, %eax is the biggest | |
| start_loop: #start loop | |
| cmp1 $0, %eax #check to see if we've hit the end | |
| je loop_exit | |
| incl %edi #load next value | |
| mov1 data_items(,%edi,4), %eax | |
| cmp1 %ebx, %eax #compare values | |
| jle start_loop #jump to loop beginning of the new one isn't bigger | |
| movl %eax, %ebx #move the value as the largest | |
| jmp start_loop #jump to loop beginning | |
| loop_exit: | |
| # %ebx is the status code for the exit system call and it already has the maximum number | |
| movl $1, %eax #1 is the exit() syscall | |
| int $0x80 | |
| Now assemble and link it | |
| as maximum.s -0 maximum.o | |
| ld maximum.o -0 maximum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment