[mweeks@gsuad.gsu.edu@snowball ~]$ cat table_select.asm ; Assemble: nasm -f elf64 table_select.asm ; Link: gcc table_select.o -o table_select ; Based on code from Irvine's chapter 6, slides 59--61. ; This is expanded into a program and adapted for NASM. -MCW extern printf ; We will use this external function extern puts ; We will use this external function section .data ; Data section, initialized variables CaseTable: db 'A' ; lookup value dq Process_A EntrySize equ ($ - CaseTable) db 'B' dq Process_B db 'C' dq Process_C db 'D' dq Process_D NumberOfEntries equ ($ - CaseTable) / EntrySize mystr1: db "Process %c", 10, 0 mystr2: db "Finished", 10, 0 section .text global main main: mov al, 'B' ; test if B works mov ebx,CaseTable ; point EBX to the table mov ecx,NumberOfEntries ; loop counter L1: cmp al,[ebx] ; match found? jne L2 ; no: continue call NEAR [ebx + 1] ; yes: call the procedure call WriteString ; display message jmp L3 ; and exit the loop L2: add ebx,EntrySize ; point to next entry loop L1 ; repeat until ECX = 0 L3: mov rax, 0 ret Process_A: push rbx push rcx mov rsi, 'A' ; print the letter A mov rax, 0 mov rdi, mystr1 call printf pop rcx pop rbx ret Process_B: push rbx push rcx mov rsi, 'B' ; print the letter B mov rax, 0 mov rdi, mystr1 call printf pop rcx pop rbx ret Process_C: push rbx push rcx mov rsi, 'C' ; print the letter C mov rax, 0 mov rdi, mystr1 call printf pop rcx pop rbx ret Process_D: push rbx push rcx mov rsi, 'D' ; print the letter D mov rax, 0 mov rdi, mystr1 call printf pop rcx pop rbx ret WriteString: push rbx push rcx mov rdi, mystr2 call puts pop rcx pop rbx ret [mweeks@gsuad.gsu.edu@snowball ~]$ nasm -f elf64 table_select.asm [mweeks@gsuad.gsu.edu@snowball ~]$ gcc table_select.o -o table_select [mweeks@gsuad.gsu.edu@snowball ~]$ ./table_select Process B Finished [mweeks@gsuad.gsu.edu@snowball ~]$