Skip to content

Instantly share code, notes, and snippets.

@shanenoi
Created November 18, 2020 14:23
Show Gist options
  • Save shanenoi/337207e81bb53c6b6778f0b38ff135db to your computer and use it in GitHub Desktop.
Save shanenoi/337207e81bb53c6b6778f0b38ff135db to your computer and use it in GitHub Desktop.
Ideas are coming up
# Make Assembly Great Again(linux)!!! #
[+] Hello world
````
section .data
msg db 'Hello, world!' ;string to be printed
len equ $ - msg ;length of the string
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
````
[+] Component
[-] Declare variable
(data section)
````
section .data
<var name> <type> <init var>
````
DB Define Byte allocates 1 byte
DW Define Word allocates 2 bytes
DD Define Doubleword allocates 4 bytes
DQ Define Quadword allocates 8 bytes
DT Define Ten Bytes allocates 10 bytes
(bss section)
````
section .bss
<var name> <type> <size>
````
RESB Reserve a Byte
RESW Reserve a Word
RESD Reserve a Doubleword
RESQ Reserve a Quadword
REST Reserve a Ten Bytes
[-] Constant
(data section or outside:3 )
````
<const name> equ <value>
````
(By %assign, it can be redefined)
````
%assign <const name> <value>
````
[-] Body
````
_start:
;
; code here
;
mov eax, 1 ; call exit number
int 0x80 ; call kernel
````
[-] Start program
````
segment .text
global _start
````
[+] Input
[-] Declare Var
````
section .bss
<var name> resb <size>
````
[-] In Body
````
mov eax, 3
mov ebx, 2
mov ecx, num
mov edx, <size>
int 80h
````
[+] Change Value of Var
[-] Common Type Specifiers
BYTE 1
WORD 2
DWORD 4
QWORD 8
TBYTE 10
[-] Change with a determined value
````
mov [<var name>], <type> 'value'
````
[-] Change with a var
````
mov [<var name 1>], <var name 2>
````
[+] Length Of String
[-] In Data Section
(It must be constant)
````
<const name> equ $- <string var>
````
[+] INC/DEC operation
[-] Register
````
INC/DEC <register name>
````
[-] Var
````
INC/DEC [<var name>]
````
[+] ADD/SUB operation
[-] It can
Register to register
Memory to register
Register to memory
Register to constant data
Memory to constant data
It will not return a negative number!!!
[-] More about this operation
Subtracting ascii '0' to convert the number into a decimal number.
Adding '0' to to convert the number from decimal to ASCII
[-] How to do it
````
ADD eax, ebx ; look like eax += ebx
SUB eax, ebx ; look like eax -= ebx
````
[+] MUL/IMUL operation
[-] How to do it
````
MOV al, <var1>
SUB al, '0'
MOV bl, <var2>
SUB bl, '0'
MUL/IMUL bl
ADD al, '0'
MOV [<result var>], al
````
[+] DIV/IDIV operation
[-] How to do it
````
MOV al, <var1>
SUB al, '0'
MOV bl, <var2>
SUB bl, '0'
DIV/IDIV bl
ADD al, '0'
MOV [<result var>], al
````
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment