//---------------------------------------------------------------- // fifty.s (For you to 'debug' during our Final Exam) // // This program adds the first fifty positive integers, // then tells the user whether that sum is odd or even. //---------------------------------------------------------------- .equ N, 50 # the maximum summand sum: .short 0 # holds running total emsg: .string "The sum is even\n" # reports an even sum elen: .int . - emsg # length of message omsg: .string "The sum is odd\n" # reports an odd sum olen: .int . - olen # length of message .text _start: # add up the first N positive integers movl $1, %eax # the initial summand nxadd: addl %eax, sum # add current summand incl %eax # set up next summand cmpl N, %eax # does EAX exceed N? jng nxadd # no, do another add # ok, see whether the total is even or odd movl sum, %eax # copy total into EAX shrl $1, %eax # lowest bit to Carry jnc isevn # CF == 0? yes, even jmp isodd # otherwise, odd sum isevn: # report that the total was an even number movl emsg, %ecx # message-address movl elen, %edx # message-length jmp finis # jump to finish isodd: # report that the total was an odd number movl omsg, %ecx # message-address movl olen, %edx # message-length jmp finis # jump to finish finis: # program shows report, then terminates movl $4, %eax # system-call ID-number movl $1, %ebx # device-file ID-number int $0x80 # enter Linux kernel .end # end of program text #-----------------------------------------------------------------