Skip to content

Instantly share code, notes, and snippets.

View 0x61nas's full-sized avatar
💭
I may be slow to respond.

0x61nas

💭
I may be slow to respond.
View GitHub Profile

Implicit Operands

Some instructions act on registers or even memory locations that are not stated in a list of operands. These instruction does do in fact have operands, but they represent assumptions made by the instruction. Implicit operands dose not change and cannot be changed. Most of the instruction that have implicit opeands dose have explicit operands as well.

MUL

The MUL instruction multiplies two values and returns the product. However, multiplication has a special problem: It generates output values that are often hugely lager than the input values. think of 0xffffffff * 0xffffffff. So to solve this problem the MUL instructison uses an implicit operands to store the product: by using two registers to hold our product.

[!Note]

@0x61nas
0x61nas / X86-64_GENERAL_PURPOSE_REGISTERS
Last active February 11, 2024 11:41
The general purpose registers(GPRs) in x64 processors
All x86-64 processors contain 16 64-bit wide general purpose registers.
Functions use thes registers to perform integer arithmetic, bitwise logical operations, comparisoins, address calculations, and data transfers.
A function can also store an intermediate or temporary result in one of those registres instead of saving it to memory.
╭──────────────────────────────────Quad Word────────────────────────────────────╮
│ ╭─────────────────Double Word────────────────╮│
│ │ ╭───────Word────────╮││
│ │ │ ╭─Byte──╮│││
╵ ╵ ╵ ╵ ╵╵╵╵
┇63 ┇31 ┇15 ┇7 0┃
@0x61nas
0x61nas / brain-tumor-detection.ipynb
Created February 10, 2024 23:28
Brain Tumor Detection.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Instruction Operands Description
MOV dist, source Copy the data from the source to the distnation register or memory
INC dist Increment the distnation register or memory by one
DEC dist Decrement the distnation register or memory by one
JNZ dist(label) Tests the value of Zero Flag and jump to the distnation if its not set(a.k.a. set o 0)
JMP dist Always jump to its operand
ADD dist, source Add the source value to the distnation
NOP n/a No operation, it takes some time to execute
@0x61nas
0x61nas / RFLAGS.md
Last active February 6, 2024 16:52

RFlags is like a veritable junk drawer of disjointed little bits of information. RFlags as a whole is a single 64-bit register buried inside he CPU. It's the 64-bit extension of the 32-bit EFlags register, which in turn is the 32-bit extension of the 16-bit Flags register. There's only 18 bits of the RFlags register are actually flags. The reset is reserved for later use in future generations of Intel CPUs. A flag is a single bit of information, whose meaning is independent from any other bits. A bit can be set to 1 or clered to 0 by the CPU as its needs require.

I Shorthand Name Description
0 CF Carry Flag Used in assigned arithmetic operations. If the result of arithmetic or shift operation carries out a bit from the operand.
1 - Undefind -
2 PF Parity Flag Indecates whether the number of set (1) bits in the low-order byte of a result is even(set), or odd(cleard).
exit
break start
exit
n
i reg
i reg cl
i reg dh
exit
n
i reg eax
; MOV instruction
; Used to move a byte, word(16bit), double word(32bit), or quad word(64bit) from the source(second operand) to the dist(first operand).
; **Note** that the MOV instruction cannot move data directly from one address in memory to different address in memory
; to do that you need to _two separate MOV instructions: frst move the datat from the memory to some registry and then move it from that registry to the dist memory.
; Assemble with:
; nasm -f elf64 -g -F dwarf mov101.asm
; ld -o mov101 mov101.o
section .data
section .text
; Print a message out
; Aassmbl with:
; nasm -f elf64 -g -F stabs eatsyscall.asm
; ld -o eatsyscall eatsyscall.o
section .data
EatMsg: db "Eat at Joe's!", 10
EatLen: equ $-EatMsg
section .bss ; section containing the unintialized data
section .data
section .text
global .start
start:
; When you want to put the value 0 into a register, the fastest way is to use XOR.
; XORing a value againsnt it self yields 0.
xor rbx, rbx
; Yes, you could use `mov rbx, 0` instnad, but that has to go out to memory to load the immediate value 0
; XORing register against it self doesn't go out of the CPU for either the source or the destination, so its a little bit faster.
; Data stored inside CPU register called _register data_.
; and accessing register data directly is addressing mode called _register addressing_
section .data
section .text
global .start
start:
mov rbp, rsi ; 64-bit
mov ecx, edx ; 32-bit