iAPX86 code for ABS (using Microsoft C?)

Walter Bright bright at Data-IO.COM
Thu Aug 3 04:05:06 AEST 1989


In article <1202 at draken.nada.kth.se> d88-eli at nada.kth.se (Erik Liljencrantz) writes:
>The function to convert an integer
>to a positive integer was performed without a conditional jump (i.e. JS or
>something). I'm very interested in this piece of code,

This is a well-known trick:

;;;;;;;;;;;;;;;;;;;;;;;;;
; Take absolute value of integer.

	c_public abs

func	abs
	push	BP
	mov	BP,SP
	mov	AX,P[BP]
	cwd
	xor	AX,DX		;look, ma, no jumps!
	sub	AX,DX
	pop	BP
	ret
c_endp	abs



More information about the Comp.lang.c mailing list