Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Assembly work for Asssignment
- ;
- ; Course: Assembly Programming for all Platforms
- ;
- ; Copyright (C) 2022 UNIXn3rdV
- ; Macros takes 2 arguments and will be required to use
- ;
- ;
- %macro print_line 2
- mov eax, 4 ; sys_write call
- mov ebx, 1 ; use a file descriptor (fd) - Screen
- mov ecx, %1 ; Data in to buffer
- mov edx, %2 ; send no of bytes to buffer
- int 0x80 ; call kernel interupt
- ; Sys_write system call (EAX is 32 Bit while RAX is 64 Bit)
- ;
- ; EAX Arg1 (EBX) Arg2 (ECX) Arg3 (EDX)
- ; 4 fd String Bytes of string
- ;
- %endmacro
- %macro print_Linux_lines 2
- mov eax, 4 ; sys_write call
- mov ebx, 1 ; use a file descriptor (fd) - Screen
- mov ecx, %1 ; Data in to buffer
- mov edx, %2 ; send no of bytes to buffer
- int 0x80 ; call kernel interupt
- ; Add a newline after print
- mov eax, 4
- mov ebx, 1
- mov ecx, newline
- mov edx, nllen
- int 0x80
- %endmacro
- ; similar to the C putchar
- %macro putchar 2
- mov eax, 4
- mov ebx, 1
- mov ecx, %1
- mov edx, %2
- int 0x80
- ; Add a space after the charactor
- mov eax, 4
- mov ebx, 1
- mov ecx, space
- mov edx, splen
- int 0x80
- %endmacro
- %macro read_line 2
- mov eax, 3 ; sys_read call
- mov ebx, 1 ; use file descriptor (fd) - Keyboard
- mov ecx, %1 ; output buffer
- mov edx, %2 ; size
- int 0x80 ; call kernel interrupt
- ; Sys_read system call
- ;
- ; EAX Arg1 (EBX) Arg2 (ECX) Arg3 (EDX)
- ; 3 fd Variable Bytes of variable
- ;
- %endmacro
- ; Data Section will contain values to be addressed in memory before
- ; compilation of the program
- ;
- section .data
- newline: db ' ', 0xA ; New line
- nllen: equ $-newline
- space: db ' ', 0 ; Space
- splen: equ $-space
- progn: db 'Assembly assignment program',0xA ; Program name (db = define bytes)
- pglen: equ $-progn ; Program name length in bytes calculation
- copyr: db 'Copyright (C) 2022 UNIXnerd',0xA,0xA ; copyright message
- crlen: equ $-copyr ; copyright length in bytes calculation
- prompt1: db 'Please Enter your name: ', 0 ; Prompt a user
- prmptlen: equ $-prompt1
- hello: db 'Hello, ', 0 ; Hello
- helen: equ $-hello
- ASCIIShow: db 'Now we are going to show all non-extended ASCII Charactors', 0xA
- ASClen: equ $-ASCIIShow
- asm: db 'Made in Assembly (Linux)', 0
- asmlen: equ $-asm
- ; Section for variables reserving memory in bytes for future
- ; use in the program
- ;
- section .bss
- name: resb 20 ; reserve 20 bytes for a name - for input
- char: resb 5 ; this is for ascii charactor related
- no: resb 2 ; Number to use for edx
- ; This is where most of code will be
- section .text
- global _start
- _start:
- print_line progn, pglen ; Display Program name
- print_line copyr, crlen ; Display Copyright
- print_line prompt1, prmptlen ; Show Prompt
- read_line name, 20 ; Take input
- print_line newline, nllen ; Line Spacing
- print_line hello, helen ; Display Hello
- print_line name, 20 ; display name
- print_line newline, nllen ; Line Spacing
- print_line ASCIIShow, ASClen ; Display message on ASCII Charactor display
- print_line newline, nllen ; Line Spacing
- ; Display ASCII Charactors
- mov esi, 48 ; Start ASCII at 48
- call print_ascii
- print_line newline, nllen ; Line Spacing
- print_line newline, nllen ; Line Spacing
- mov edi, 1 ; for printing linux line
- mov [no], edi
- call print_Linux
- print_line newline, nllen ; Line Spacing
- call sys_exit ; exit the program
- print_ascii:
- mov [char], esi ; put value in to variable
- putchar char, 1 ;
- inc esi
- ;add esi, 1
- cmp esi, 126 ; 126 is final charactor
- jle print_ascii ; jump back to start of block until 126 is reached
- ret
- print_Linux:
- mov [no], edi
- print_Linux_lines asm, [no] ; no must be in brackets (Variable) or it will over run.
- inc edi
- cmp edi, asmlen ; compare value with total length of linux line
- jle print_Linux
- ret
- sys_exit:
- mov eax, 1 ; sys_exit call
- mov ebx, 0 ; show exit code 0
- int 0x80 ; interrupt the kernel
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement