while reading the assembly output of a simple program built with the Go compiler I could not make sense of the string comparison implementation.
The program is like
package main
import (
"fmt"
"os"
)
func main() {
fmt.Print("Enter the value: ")
var v string
fmt.Fscanf(os.Stdin, "%v", &v)
if v != "123456" {
fmt.Println("exit")
os.Exit(2)
}
fmt.Println("v=", v)
}
In below extract, what does it do at 0x48bd94
and 0x48bd9d
?
$ objdump --disassemble=main.main ./z
...
48bd85: 48 8b 54 24 38 mov 0x38(%rsp),%rdx
48bd8a: 4c 8b 02 mov (%rdx),%r8
48bd8d: 48 83 7a 08 06 cmpq $0x6,0x8(%rdx)
48bd92: 75 12 jne 48bda6 <main.main+0xe6>
48bd94: 41 81 38 31 32 33 34 cmpl $0x34333231,(%r8)
48bd9b: 75 09 jne 48bda6 <main.main+0xe6>
48bd9d: 66 41 81 78 04 35 36 cmpw $0x3635,0x4(%r8)
48bda4: 74 49 je 48bdef <main.main+0x12f>
...