Online Compiler Nasm

extern io_get_char, io_print_udec, io_newline section .text global main main: call io_get_char mov ebx, eax call io_get_char mov ecx, eax call io_get_char call io_get_char mov esi, eax call io_get_char mov edi, eax sub ebx, 'A' sub ecx, '1' sub esi, 'A' sub edi, '1' sub ebx, esi mov eax, ebx sar eax, 31 mov edx, eax xor ebx, eax sub ebx, edx sub ecx, edi mov eax, ecx sar eax, 31 mov edx, eax xor ecx, eax sub ecx, edx add ebx, ecx mov eax, ebx call io_print_udec call io_newline xor eax, eax ret
1) This code reads five characters, interprets them as chessboard coordinates (like "A1 B2"), calculates the Manhattan distance between two positions on a chessboard, and prints the result as an unsigned decimal number.

2) Hint: The `sar eax, 31` instruction is used to create a mask for absolute value calculation. After subtracting the coordinates, this sequence computes the absolute value of the difference.

Hint: The first three `io_get_char` calls read the first coordinate (like 'A', '1', and space), while the next two read the second coordinate. The space character is read but not used in calculations.