# compiled with -O2, gpc 20021128, gbe 3.1.1, on i586 # # procedure Mod_I (var Z: Integer; X, Y: Integer); # begin # Z := X mod Y # end; pushl %ebp # prologue movl %esp, %ebp pushl %edi pushl %esi pushl %ebx subl $12, %esp movl 16(%ebp), %ebx # %ebx := Y movl 12(%ebp), %esi # %esi := X testl %ebx, %ebx jle .L23 # if Y <= 0: error testl %esi, %esi js .L16 # X >= 0? # yes: movl %esi, %edx # sign-extend X to 64 bits; movl %esi, %eax # here X is non-negative, hence sarl $31, %edx # `xorl %edx, %edx' would suffice idivl %ebx # %edx := X mod Y movl %edx, %ecx # %ecx := %edx testl %edx, %edx je .L15 xorl %ebx, %esi js .L24 # if (%edx<>0)&(sgn(X)<>sgn(Y)): %ecx += Y # - always false! .L15: movl 8(%ebp), %eax movl %ecx, (%eax) # Z := %ecx leal -12(%ebp), %esp # epilogue popl %ebx popl %esi popl %edi popl %ebp ret .L24: # never executed! addl %ebx, %ecx jmp .L15 .p2align 4,,7 .L16: # X < 0: movl %esi, %edi negl %edi # %edi := -X movl %edi, %edx # sign-extend -X to 64 bits; movl %edi, %eax # it is always positive (*) sarl $31, %edx idivl %ebx # %edx := (-X) mod Y movl %edx, %ecx # %ecx := %edx testl %edx, %edx je .L19 # if %edx = 0: return 0 movl %edi, %esi xorl %ebx, %esi js .L25 # if sgn (Y) <> sgn (-X): %ecx += Y # - always false (*) .L21: testl %ecx, %ecx je .L19 # if %ecx = 0: return 0 # - always false! movl %edi, %edx # recompute %edx := (-X) mod Y movl %edi, %eax # once again (!) sarl $31, %edx idivl %ebx testl %edx, %edx je .L22 # if %edx = 0: return Y (!?) # - always false! testl %esi, %esi js .L26 # if sgn (Y) <> sgn (-X): %edx += Y # - always false (*) .L22: movl %ebx, %ecx # return Y - %edx subl %edx, %ecx jmp .L15 .L26: # never executed (*) addl %ebx, %edx jmp .L22 .p2align 4,,7 .L19: # return 0: xorl %ecx, %ecx # %ecx is already 0 here! jmp .L15 .L25: # never executed (*) addl %ebx, %ecx jmp .L21 .L23: # Y <= 0: runtime error subl $12, %esp pushl $714 call _p_error # (*) well, this is not quite true if X = -maxint - 1; but then # using 0 instead of sign-extension would be correct as well, # and it would save a lot of trouble later