Unlike high-level languages, assembly is architecture-specific (x86-64 code doesn't run on ARM), gives direct control over registers and memory, and has no built-in types, loops or functions — you build them from jumps, the stack and conventions.
Key takeaways
- 50 Assembly Language interview questions, grouped by level: freshers, intermediate, experienced and coding.
- Every answer starts with a one-line “Quick answer” you can say out loud, followed by the explanation and runnable code.
- Use the filter bar to practise only the level you are interviewing for, then test yourself with the free Assembly Language quiz.
What is Assembly Language, and why do interviewers ask about it?
Assembly language is a human-readable form of a processor's machine instructions. Engineers use it to understand how compiled code really runs — for embedded and firmware work, operating systems, compilers, performance tuning, reverse engineering and security research.
These assembly interview questions focus on x86-64 (NASM/Intel syntax on Linux), the architecture most interviews use, with notes on ARM where relevant. They cover registers, addressing modes, the stack and calling conventions, flags and branching, system calls, SIMD and the debugging skills interviewers test for systems, embedded and security roles.
Why companies hire for Assembly Language
- Required knowledge for embedded, firmware, OS and compiler roles
- Essential for reverse engineering, malware analysis and exploit development
- Helps you read compiler output and optimise hot code
- Builds a deep understanding of memory, the stack and CPU behaviour
Basic Assembly Language Interview Questions for Freshers
15 questionsStart here if you are a fresher or switching to Assembly Language. These fundamentals are asked in almost every first-round and campus interview.
- Assembler: translates assembly source into an object file containing machine code, symbols and relocation entries (
nasm -f elf64 prog.asm) - Linker: combines object files and libraries, resolves symbol addresses and produces an executable or shared library (
ld prog.o -o prog) - Loader: part of the OS that maps the executable into memory, sets up the stack, loads shared libraries (the dynamic linker) and jumps to the entry point
Conventional roles: rax holds return values and syscall numbers; rsp is the stack pointer; rbp is often the frame pointer; rip is the instruction pointer (not directly writable); rflags holds the status flags.
eax) zero-extends into the full 64-bit register. Writing 8-bit or 16-bit parts does not.How interviewers ask it“Can you compare Intel and AT&T syntax? Where do people usually confuse them?”
What is the difference between Intel and AT&T syntax?
| Intel (NASM, MASM) | AT&T (GAS, GCC default) | |
|---|---|---|
| Operand order | mov dest, src | movq src, dest |
| Registers | rax | %rax |
| Immediates | 5 | $5 |
| Memory | [rbp-8] | -8(%rbp) |
| Size | Inferred, or qword ptr | Suffix: b, w, l, q |
objdump -M intel and gcc -masm=intel switch the output to Intel syntax.
mov rax, 42 ; immediate -> register
mov rbx, rax ; register -> register
mov [rbp-8], rbx ; register -> memory (64-bit)
mov ecx, [rbp-8] ; memory -> register (32-bit, zero-extends into rcx)
mov byte [rdi], 0 ; size must be explicit for immediate -> memoryHow interviewers ask it“Let's start with the basics — how would you explain addressing modes in x86-64?”
What are addressing modes in x86-64?
- Immediate:
mov rax, 10 - Register:
mov rax, rbx - Direct (absolute or RIP-relative):
mov rax, [rel counter] - Register indirect:
mov rax, [rbx] - Base + displacement:
mov rax, [rbp-16] - Base + index × scale + displacement:
mov eax, [rbx + rcx*4 + 8]— ideal for arrays (scale can be 1, 2, 4 or 8)
; eax = arr[i] where arr is an int32 array in rdi and i is in rsi
mov eax, [rdi + rsi*4]push rbx ; rsp -= 8 ; [rsp] = rbx
push rax
pop rax ; rax = [rsp] ; rsp += 8
pop rbx ; restore in reverse order (LIFO)- ZF (zero): the result was zero
- SF (sign): the result was negative (top bit set)
- CF (carry): unsigned overflow or borrow
- OF (overflow): signed overflow
- PF (parity) and AF (auxiliary carry), which are rarely used
cmp a, b performs a - b and sets the flags without storing the result; test a, b performs a AND b the same way.
How interviewers ask it“Live coding: Implement if-else in Assembly. Talk me through your approach first.”
How do you implement if-else in assembly?
; if (a > b) max = a; else max = b; (signed, a in edi, b in esi)
cmp edi, esi
jle .else
mov eax, edi
jmp .done
.else:
mov eax, esi
.done:
; Branch-free alternative:
; mov eax, esi
; cmp edi, esi
; cmovg eax, ediHow interviewers ask it“Can you compare signed and unsigned conditional jumps? Where do people usually confuse them?”
What is the difference between signed and unsigned conditional jumps?
| Condition | Signed | Unsigned |
|---|---|---|
| greater | jg / jnle | ja / jnbe |
| greater or equal | jge | jae / jnb |
| less | jl | jb / jc |
| less or equal | jle | jbe |
Signed jumps use SF and OF; unsigned jumps use CF and ZF. Using the wrong family is a classic bug — for example, treating -1 as greater than 5.
How interviewers ask it“Can you write a loop in Assembly? Then walk me through the edge cases you would test.”
How do you write a loop in assembly?
; sum = 0; for (i = 0; i < n; i++) sum += arr[i]; arr=rdi, n=rsi
xor eax, eax ; sum = 0
xor ecx, ecx ; i = 0
.loop:
cmp rcx, rsi
jge .end
add eax, [rdi + rcx*4]
inc rcx
jmp .loop
.end:
ret ; result in eaxThe loop instruction exists (it decrements rcx and jumps if non-zero) but is slower on modern CPUs, so compilers avoid it.
- .text: executable code (read-only, executable)
- .data: initialised global and static data (read-write)
- .rodata: read-only constants such as string literals
- .bss: uninitialised data that is zero-filled at load time and takes no space in the file
section .data
msg db "Hello, World!", 10 ; 10 = newline
msglen equ $ - msg
section .bss
buffer resb 64 ; 64 zeroed bytes
section .text
global _startsection .data
msg db "Hello, World!", 10
len equ $ - msg
section .text
global _start
_start:
mov rax, 1 ; sys_write
mov rdi, 1 ; fd = stdout
lea rsi, [rel msg] ; buffer
mov rdx, len ; length
syscall
mov rax, 60 ; sys_exit
xor edi, edi ; status 0
syscall
; Build: nasm -f elf64 hello.asm && ld hello.o -o helloHow interviewers ask it“How is mov different from lea, and when does the difference matter in practice?”
What is the difference between mov and lea?
lea rsi, [rel msg] ; rsi = address of msg
mov al, [rsi] ; al = first byte of msg
lea eax, [rdi + rdi*2] ; eax = rdi * 3 (no flags changed)
lea rax, [rbx + rcx*8 + 16] ; address of element in a struct/arrayIntermediate Assembly Language Interview Questions
15 questionsQuestions for candidates with 1–3 years of experience — the concepts interviewers use to check that you have actually built things with Assembly Language.
How interviewers ask it“Walk me through a function prologue and epilogue in Assembly. Where does it come up in real systems?”
What is a function prologue and epilogue?
my_func:
push rbp ; prologue: save caller's frame pointer
mov rbp, rsp ; new frame base
sub rsp, 32 ; space for locals (keep rsp 16-byte aligned)
; ... locals at [rbp-8], [rbp-16] ...
mov rsp, rbp ; epilogue (or: leave)
pop rbp
retOptimised code often omits the frame pointer (-fomit-frame-pointer) and addresses locals relative to rsp. Many teams keep frame pointers enabled for better profiling and stack traces.
How interviewers ask it“Explain the System V AMD64 calling convention (Linux and macOS), ideally with an example from a project you've worked on.”
Explain the System V AMD64 calling convention (Linux and macOS).
- Integer and pointer arguments:
rdi,rsi,rdx,rcx,r8,r9, then the stack (right to left) - Floating-point arguments:
xmm0–xmm7 - Return value:
rax(andrdxfor 128-bit),xmm0for floating point - Caller-saved (volatile):
rax,rcx,rdx,rsi,rdi,r8–r11, and the xmm registers - Callee-saved:
rbx,rbp,r12–r15(must be restored before returning) rspmust be 16-byte aligned at the point ofcall- Red zone: leaf functions may use 128 bytes below
rspwithout adjusting it
; long add3(long a, long b, long c) { return a + b + c; }
add3:
lea rax, [rdi + rsi]
add rax, rdx
retHow interviewers ask it“Walk me through caller-saved and callee-saved registers in Assembly. Where do they come up in real systems?”
What are caller-saved and callee-saved registers?
How interviewers ask it“Why must the stack be 16-byte aligned before a call — and how does that matter in practice?”
Why must the stack be 16-byte aligned before a call?
main:
sub rsp, 8 ; entry rsp is 16n+8 → realign to 16n
lea rdi, [rel fmt]
xor eax, eax ; varargs: al = number of vector registers used
call printf
add rsp, 8
xor eax, eax
retHow interviewers ask it“How would you call a C function from assembly and vice versa? Walk me through your approach.”
How do you call a C function from assembly and vice versa?
; int64_t max64(int64_t a, int64_t b); — callable from C
global max64
max64:
mov rax, rdi
cmp rdi, rsi
cmovl rax, rsi
retextern long max64(long a, long b);
printf("%ld\n", max64(3, 9)); /* 9 */; signed: rax = a / b, rdx = a % b (a in rdi, b in rsi)
mov rax, rdi
cqo ; sign-extend rax into rdx:rax
idiv rsishl/sal— shift left (multiply by powers of 2)shr— logical shift right (unsigned divide by 2ⁿ, zero-filled)sar— arithmetic shift right (signed; keeps the sign bit, rounds toward −∞)rol/ror— rotate bits around (used in hashing and cryptography)
shl eax, 3 ; eax *= 8
shr ecx, 1 ; unsigned /2
sar edx, 31 ; edx = 0 or -1 depending on the sign (common trick)How interviewers ask it“Suppose you need to access an array of structures in Assembly — how do you approach it, and what can go wrong?”
How do you access an array of structures in assembly?
; struct Point { int32 x; int32 y; }; (8 bytes)
; return points[i].y — points in rdi, i in rsi
mov eax, [rdi + rsi*8 + 4]How interviewers ask it“Explain string instructions like rep movsb and rep stosb in Assembly in detail — what should a new team member understand about them?”
What are string instructions like rep movsb and rep stosb?
; memset(dst=rdi, 0, n=rdx)
mov rcx, rdx
xor eax, eax
rep stosbHow interviewers ask it“How is test different from cmp, and when does the difference matter in practice?”
What is the difference between test and cmp?
test rax, rax ; is rax zero? (shorter than cmp rax, 0)
jz .is_zero
test al, 1 ; is the lowest bit set? (odd number)
jnz .is_odd
cmp rdi, rsi ; compare two values
jl .less ; signed rdi < rsiHow interviewers ask it“Explain position-independent code (PIC) and RIP-relative addressing in Assembly in detail — what should a new team member understand about them?”
What are position-independent code (PIC) and RIP-relative addressing?
default rel
lea rdi, [msg] ; RIP-relative, works at any load address
call printf wrt ..plt ; external call via the PLT (NASM syntax)Advanced Assembly Language Interview Questions for Experienced Developers
12 questionsSenior-level Assembly Language questions on internals, performance, design and trade-offs — typical for 3, 5 and 7+ years of experience.
How interviewers ask it“Walk me through interrupts and exceptions on x86. Where do they come up in real systems?”
What are interrupts and exceptions on x86?
How interviewers ask it“How would you explain protection rings and privilege levels to a junior engineer, and what do people most often get wrong?”
What are protection rings and privilege levels?
; add 8 floats: c[i] = a[i] + b[i] (a=rdi, b=rsi, c=rdx, 32-byte aligned)
vmovaps ymm0, [rdi]
vaddps ymm0, ymm0, [rsi]
vmovaps [rdx], ymm0
vzeroupper ; avoid AVX-SSE transition penalties before returning; atomic increment and return the old value: old = fetch_add(&counter, 1)
mov eax, 1
lock xadd [rdi], eax ; eax = old value, [rdi] += 1How interviewers ask it“How does compare-and-swap (cmpxchg) work under the hood? Take me through it step by step.”
How does compare-and-swap (cmpxchg) work?
; spinlock acquire: while (!CAS(lock, 0, 1)) pause;
acquire:
mov ecx, 1
.retry:
xor eax, eax
lock cmpxchg [rdi], ecx
je .got
pause ; be polite to the sibling hyper-thread
jmp .retry
.got:
ret- Stack canaries (
-fstack-protector): a random value checked beforeret - NX/DEP: the stack isn't executable, which defeats injected shellcode
- ASLR + PIE: randomised addresses
- CET shadow stacks / control-flow integrity: hardware-checked return addresses
- Safe coding: bounds-checked APIs (
snprintf,strlcpy), fuzzing
Attackers respond with return-oriented programming (ROP), which is why layered defences matter.
How interviewers ask it“Suppose you need to debug assembly with GDB — how do you approach it, and what can go wrong?”
How do you debug assembly with GDB?
gdb ./prog
(gdb) set disassembly-flavor intel
(gdb) layout asm # TUI with disassembly
(gdb) layout regs # show registers
(gdb) break *_start # breakpoint at an address/symbol
(gdb) run
(gdb) stepi / nexti # step one instruction (into / over calls)
(gdb) info registers rax rsp
(gdb) x/8gx $rsp # examine 8 quadwords at the stack pointer
(gdb) x/s $rsi # examine memory as a stringTools such as GEF or pwndbg add richer views. objdump -d -M intel gives static disassembly.
How interviewers ask it“How would you read compiler-generated assembly? Walk me through your approach.”
How do you read compiler-generated assembly?
; branch-free abs(x): edi -> eax
mov eax, edi
neg eax
cmovl eax, edi ; if -x < 0 then x was positive: use x// AArch64: return a + b (args in x0, x1; result in x0)
add x0, x0, x1
retAssembly Language Coding Interview Questions (Programs with Code)
8 questionsHands-on Assembly Language programs that are asked in coding rounds and machine tests. Read the code, then try writing it yourself without looking.
; size_t my_strlen(const char *s) s in rdi
global my_strlen
my_strlen:
mov rax, rdi
.loop:
cmp byte [rax], 0
je .done
inc rax
jmp .loop
.done:
sub rax, rdi ; length = end - start
ret; int max_array(const int *a, size_t n) a=rdi, n=rsi (n >= 1)
global max_array
max_array:
mov eax, [rdi]
mov ecx, 1
.loop:
cmp rcx, rsi
jae .done
mov edx, [rdi + rcx*4]
cmp edx, eax
cmovg eax, edx
inc rcx
jmp .loop
.done:
ret; uint64_t fact(uint64_t n) n in rdi
global fact
fact:
cmp rdi, 1
ja .recurse
mov eax, 1
ret
.recurse:
push rbx ; callee-saved (also keeps rsp 16-byte aligned for the call)
mov rbx, rdi
lea rdi, [rdi - 1]
call fact ; rax = fact(n-1)
imul rax, rbx ; rax *= n
pop rbx
ret; void reverse(char *s, size_t len) s=rdi, len=rsi
global reverse
reverse:
test rsi, rsi
jz .done
lea rdx, [rdi + rsi - 1] ; end pointer
.loop:
cmp rdi, rdx
jae .done
mov al, [rdi]
mov cl, [rdx]
mov [rdi], cl
mov [rdx], al
inc rdi
dec rdx
jmp .loop
.done:
retHow interviewers ask it“Can you swap two variables in assembly without a temporary register? Then walk me through the edge cases you would test.”
How do you swap two variables in assembly without a temporary register?
xchg rax, rbx ; simplest (register-register xchg is not locked)
; XOR swap
xor rax, rbx
xor rbx, rax
xor rax, rbxIn real code a temporary register is usually just as fast or faster — compilers often eliminate the moves entirely.
How interviewers ask it“Can you count set bits (population count) in a register in Assembly? Then walk me through the edge cases you would test.”
How do you count set bits (population count) in a register?
popcnt rax, rdi ; hardware popcount
; Portable: count = 0; while (x) { x &= x - 1; count++; }
xor eax, eax
.loop:
test rdi, rdi
jz .done
lea rcx, [rdi - 1]
and rdi, rcx
inc eax
jmp .loop
.done:
ret; int is_prime(uint64_t n) n in rdi → eax = 1/0
global is_prime
is_prime:
xor eax, eax
cmp rdi, 2
jb .ret ; 0,1 → not prime
je .yes ; 2 → prime
test dil, 1
jz .ret ; even → not prime
mov rcx, 3
.loop:
mov rax, rcx
mul rcx ; rdx:rax = rcx*rcx (rdx is clobbered)
jc .yes ; i*i overflowed past n → prime
cmp rax, rdi
ja .yes ; i*i > n → prime
mov rax, rdi
xor edx, edx
div rcx ; rdx = n % i
test rdx, rdx
jz .no
add rcx, 2
jmp .loop
.yes:
mov eax, 1
ret
.no:
xor eax, eax
.ret:
retHow interviewers ask it“Can you read input from stdin with a syscall in Assembly? Then walk me through the edge cases you would test.”
How do you read input from stdin with a syscall?
section .bss
buf resb 128
section .text
global _start
_start:
xor eax, eax ; sys_read
xor edi, edi ; fd 0 = stdin
lea rsi, [rel buf]
mov edx, 128
syscall ; rax = bytes read
mov rdx, rax ; echo it back with sys_write
mov eax, 1
mov edi, 1
lea rsi, [rel buf]
syscall
mov eax, 60
xor edi, edi
syscallPractise with the free Assembly Language quiz
Multiple-choice questions with instant feedback. Takes about 10 minutes and shows exactly which concepts to revise.
Start the Assembly Language quiz →