public
Created

Boolean vs Int in Javascript

  • Download Gist
gistfile1.asm
Assembly
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
; JavaScript Code : "!a"
movabsq $0xfff9800000000000, %r11 ; type tag of boolean (SpiderMonkey uses a trait of NaN-boxing)
cmpq %r11, %r9 ; compare with type tag of a
jne ((165)) ; if not equal jump to stub
xorl 1, %r15d ; xor value of a with 1, true is value 1 so 1^1 = 0, false is 0 so 1^0 = 1
 
; JavaScript Code: "a - 1"
movabsq $0xfff8800000000000, %r11 ; type tag of int
cmpq %r11, %r15
jne ((73)) ; jump if not int
subl $0x1, %r9d ; subtract 1
jo ((83)) ; jump if overflow
 
; JavaScript Code: "if (a)"
 
movabsq $0xfff9800000000000, %r11
cmpq %r11, %r15
jne ((86)) ; jump if not boolean
testl %r9d, %r9d ; test
jne ((95)) ; jump false
jmp ((100)) ; jump true
 
; JavaScript Code: "if (a == 1)
 
movabsq $0xfff8800000000000, %r11
cmpq %r11, %r12
jne ((70))
cmpl $0x1, %r15d
jne ((80))

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.