Assembly
Basics of Assembly programming language.
5 flashcards · Programming Languages · by lakesare
What is assembler?
Program that turns Assembly language into machine language (01000111).
What's an opcode?
First byte of an instruction in machine language, tells the hardware what operation needs to be performed with this instruction. Every processor/controller has its own set of opcodes defined in its architecture. An opcode is followed by data like address, values etc if needed.
What 3 sections does Assembly program have?
data - used for declaring initialized data or constants bss (basic service set) - used for declaring variables text - used for keeping the actual code section .data userMsg db 'Please enter a number: ' lenUserMsg equ $-userMsg dispMsg db 'You have entered: ' lenDispMsg equ $-dispMsg section .bss num resb 5 section .text global _start _start: mov eax, 4 mov ebx, 1 mov ecx, userMsg mov edx, lenUserMsg int 80h
What's the syntax of a text section?
section .text global _start _start: Must begin with the declaration global _start, which tells the kernel where the program execution begins. section .text global _start ;must be declared for linker (ld) _start: ;tells linker entry point mov edx,len ;message length mov ecx,msg ;message to write mov ebx,1 ;file descriptor (stdout) mov eax,4 ;system call number (sys_write) int 0x80 ;call kernel mov eax,1 ;system call number (sys_exit) int 0x80 ;call kernel section .data msg db 'Hello, world!', 0x…
Can you access operating system through Assembly?
Yes, through syscalls, just like in usual languages! On linux it's done by putting an argument into EAX register, and calling int 0x80. INT n/INTO/INT 3—Call to Interrupt ProcedureThe INT n instruction generates a call to the interrupt or exception handler specified with the destination operand. The destination operand specifies a vector from 0 to 255, encoded as an 8-bit unsigned intermediate value. The INT n instruction is the general mnemonic for executing a software-generated call to an int…