Opcode or operation code is between one and three bytes in
length and uniquely defines the function that is performed.
It is the data that represents a microprocessor instruction.
A CPU can perform many operations, each of these operations
is assigned a numeric code, this is the opcode. To assist in the use
of these numeric codes, mnemonics are used as textual abbreviations.
It's much easier to remember ADD than 05, for example.
A program's opcodes can be dumped from the program with objdump eg:
entropy@phalaris asm $ cat hello.s
.section .data # start the data section
hello: # the label hello whihc is the address of the first char
.ascii "Hello, World!\n\0" # .ascii defines a string
.section .text # our code start
.globl _start # the start symbol defined
_start: # the start label
nop # no operation for debugging with gdb
movl $4, %eax # mov 4 into %eax, 4 is write(descriptor, buffer, length)
movl $14, %edx # length for write 14 is the length of our string
movl $hello, %ecx # the address of our string
movl $1, %ebx # 1 is STDOUT, to the screen
int $0x80 # call the kernel
movl $1, %eax # move 1 into %eax, 1 is syscall exit()
movl $0, %ebx # move 0 into %ebx, exit's return value
int $0x80 # call kernel
entropy@phalaris asm $ as hello.s -o hello.o
entropy@phalaris asm $ ld hello.o -o hello
entropy@phalaris asm $ objdump -d hello
hello: file format elf32-i386
Disassembly of section .text:
08048094 <_start>:
8048094: 90 nop
8048095: b8 04 00 00 00 mov $0x4,%eax
804809a: ba 0e 00 00 00 mov $0xe,%edx
804809f: b9 b8 90 04 08 mov $0x80490b8,%ecx
80480a4: bb 01 00 00 00 mov $0x1,%ebx
80480a9: cd 80 int $0x80
80480ab: b8 01 00 00 00 mov $0x1,%eax
80480b0: bb 00 00 00 00 mov $0x0,%ebx
80480b5: cd 80 int $0x80
entropy@phalaris asm $
The program's op codes are the column on the left:
90
b8 04 00 00 00
ba 0e 00 00 00
b9 b8 90 04 08
bb 01 00 00 00
cd 80
b8 01 00 00 00
bb 00 00 00 00
cd 80
This is the machine code in hex that the cpu will execute.
|