#35·acwj

Part 07 precedence of comparisons

Author: minoringCreated Dec 26, 2020Updated Jun 25, 2023

I believe the precedence of arithmetic operations must have greater value than ones of comparison operator. (In OpPrec[])

For example, if input was,

print 1 + 2 < 4

then the output assembly is,

assembly
	.text
.LC0:
	.string	"%d\n"
printint:
	pushq	%rbp
	movq	%rsp, %rbp
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	movl	-4(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rdi
	movl	$0, %eax
	call	printf@PLT
	nop
	leave
	ret

	.globl	main
	.type	main, @function
main:
	pushq	%rbp
	movq	%rsp, %rbp
	movq	$1, %r8
	movq	$2, %r9
	movq	$4, %r10
	cmpq	%r10, %r9
	setl	%r10b
	andq	$255,%r10
	addq	%r8, %r10
	movq	%r10, %rdi
	call	printint
	movl $0, %eax
	popq %rbp
	ret

As you can see, they calculate 1 + (2 < 4), not (1 + 2) < 4