# anom.s -- by Vince Weaver (vince _at_ csl.cornell.edu) # 26 October 2007 # # Example code to show the fldcw instruction # counts as 2 instructions on Netburst p4 core # and one on the p6 core # Compile with: # as -o anom.o anom.s # ld -o anom anom.o # # Comment out the two fldcw instructions and watch the # instruction counts change! .globl _start _start: fldz # push zero onto x87 reg stack fstpl i # store top of stack to mem, pop # value jmp label1 # goto label 1 label2: fldl i # load value of i onto stack fnstcw w1 # store control word to mem movzwl w1,%eax # move control word into eax (zero ex) mov $0xc,%ah # set cw to "chop" (this is needed # when doing conversion to int # if you don't have SSE3 support) mov %ax,result # move updated word intp mem fldcw result # load control word from mem fistpl result # convert st(0) to int, store to w2 fldcw w1 # restore control word fldl i # load i onto st fld1 # load 1 onto st faddp %st,%st(1) # increment i fstpl i # store into mem label1: fldl i # push counter onto fp stack fldl loop_max # push contents of mem onto reg stack fucompp # compare top 2 values on stack, # pop both off. fnstsw %ax # store status word into ax sahf # store ah into flags ja label2 # jump if above exit: xor %ebx,%ebx # set to zero exit xor %eax,%eax inc %eax # put exit syscall number (1) in eax int $0x80 # and exit .data loop_max: .double 100000.0 i: .double 0 w1: .word 0 result: .word 0