//---------------------------------------------------------------- // fifty.s (Find and fix the errors in this program) // // 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 which: .ascii "evenodd" # holds missing words msg: .ascii "The sum is " # first words to show o_e: .ascii " \n" # last word goes here len: .quad . - msg # size of the message .section .text _start: # add up the first N positive integers mov sum, %rax # load starting total nxadd: inc %rax # set up next summand add %rax, sum # add the new summand cmp N, %rax # does EAX exceed N? jbe nxadd # no, do another add # ok, now divide the total by two mov sum, %rax # load total into RAX mov $2, %rbx # load divisor in RBX div %rbx # divide total by two # use remainder to 'lookup' final word for message mov which(, %rdx, 4), %eax # get four characters mov %eax, o_e # and insert into msg # use a Linux system-call to show the message-string mov $1, %rax # system-call ID-number mov $1, %rdi # device-file ID-number mov msg, %rsi # address of the string mov len, %rdx # length of the message syscall # invoke Linux service .global _start # make entry-point public #-----------------------------------------------------------------