-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d77dafe
commit 0e1daaa
Showing
4 changed files
with
600 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
%macro write_string 2 | ||
mov ebx, 1 ;file descriptor (stdout) | ||
mov eax, 4 ;system call number (sys_write);tell linker entry | ||
mov ecx, %1 ;message to write | ||
mov edx, %2 ;message length | ||
int 0x80 ;call kernel | ||
%endmacro | ||
|
||
%macro accept 2 | ||
mov ebx,0 | ||
mov eax,3 | ||
mov ecx,%1 | ||
mov edx,%2 | ||
int 0x80 ;call kernel | ||
%endmacro | ||
|
||
;======================================================================================; | ||
section .text | ||
global _start ;must be declared for using gcc | ||
_start: ;tell linker entry point | ||
; display title | ||
write_string msg,len | ||
write_string newline, len8 | ||
write_string msg1, len1 | ||
accept num1,1 | ||
write_string num1,1 | ||
write_string newline, len8 | ||
write_string msg2, len2 | ||
accept num2,1 | ||
write_string num2,1 | ||
write_string newline, len8 | ||
write_string newline, len8 | ||
|
||
mov al, byte[num1] | ||
sub al,'0' | ||
mov bl, byte[num2] | ||
sub bl,'0' | ||
add al,bl | ||
add al,'0' | ||
mov byte[ans],al | ||
|
||
|
||
; print addition | ||
write_string add_msg,len3 | ||
write_string ans,1 | ||
write_string newline,len8 | ||
|
||
mov al, byte[num1] | ||
sub al,'0' | ||
mov bl, byte[num2] | ||
sub bl,'0' | ||
sub al,bl | ||
add al,'0' | ||
mov byte[ans],al | ||
|
||
; print subtraction | ||
write_string sub_msg,len4 | ||
write_string ans,1 | ||
write_string newline,len8 | ||
|
||
mov al, byte[num1] | ||
sub al,'0' | ||
mov bl, byte[num2] | ||
sub bl,'0' | ||
mul bl | ||
add al,'0' | ||
mov byte[ans],al | ||
|
||
; print multiplication | ||
write_string mul_msg,len5 | ||
write_string ans,1 | ||
write_string newline,len8 | ||
|
||
; calculate division | ||
mov al, byte[num1] | ||
sub al,'0' | ||
mov bl, byte[num2] | ||
sub bl,'0' | ||
div bl | ||
add al,'0' | ||
add ah,'0' | ||
mov byte[ans],al | ||
mov byte[rem],ah | ||
|
||
; print division | ||
write_string div_msg,len6 | ||
write_string ans,1 | ||
write_string newline,len8 | ||
|
||
; print remainder | ||
write_string rem_msg,len7 | ||
write_string rem,1 | ||
write_string newline,len8 | ||
|
||
; end program | ||
mov eax,1 | ||
mov ebx,0 | ||
int 0x80 ;call kernel | ||
|
||
;========================================================================================; | ||
section .data | ||
msg db 'ARITHMETIC OPERATIONS', 0xa | ||
len equ $ - msg | ||
msg1 db 'Enter first number: ' | ||
len1 equ $ - msg1 | ||
msg2 db 'Enter second number: ' | ||
len2 equ $ - msg2 | ||
add_msg db 'Addition is: ' | ||
len3 equ $ - add_msg | ||
sub_msg db 'Subtraction is: ' | ||
len4 equ $ - sub_msg | ||
mul_msg db 'Multiplication is: ' | ||
len5 equ $ - mul_msg | ||
div_msg db 'Division is: ' | ||
len6 equ $ - div_msg | ||
rem_msg db 'Remainder is: ' | ||
len7 equ $ - rem_msg | ||
newline db " ", 0xa | ||
len8 equ $ - newline | ||
num1 db '0' | ||
num2 db '0' | ||
|
||
;======================================================================================; | ||
section .bss | ||
ans: resb 2 | ||
rem: resb 1 | ||
;======================================================================================; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
;MACROS DEFINITION ========================================================================== | ||
%macro write_string 2 | ||
mov ebx, 1 ;file descriptor (stdout) | ||
mov eax, 4 ;system call number (sys_write);tell linker entry | ||
mov ecx, %1 ;message to write | ||
mov edx, %2 ;message length | ||
int 0x80 ;call kernel | ||
%endmacro | ||
|
||
%macro accept 2 | ||
mov ebx,0 | ||
mov eax,3 | ||
mov ecx,%1 | ||
mov edx,%2 | ||
int 0x80 ;call kernel | ||
%endmacro | ||
;==============================================================================================; | ||
|
||
section .text | ||
global _start ;must be declared for using gcc | ||
_start: ;tell linker entry point | ||
write_string msg1, len1 | ||
write_string string_inp,string_len | ||
write_string newline, newl_len | ||
write_string msg2, len2 | ||
accept st_ind,1 | ||
write_string st_ind,1 | ||
write_string newline, newl_len | ||
write_string msg3, len3 | ||
accept en_ind,1 | ||
write_string en_ind,1 | ||
write_string newline, newl_len | ||
write_string msg4,len4 | ||
|
||
mov esi, string_inp | ||
mov byte[len_temp],string_len | ||
add byte[len_temp], 30h | ||
rpt: mov ch, [esi] | ||
mov bl, byte[st_ind] | ||
cmp bl, byte[counter] | ||
jg nextchar | ||
mov bl, byte[en_ind] | ||
cmp byte[counter], bl | ||
jg nextchar | ||
|
||
mov al, byte[esi] | ||
mov byte[print_temp], al | ||
write_string print_temp,1 | ||
|
||
nextchar: inc esi | ||
inc byte[counter] | ||
dec byte[len_temp] | ||
cmp byte[len_temp],'0' | ||
jg rpt | ||
|
||
|
||
|
||
myend: ; end program | ||
mov eax, 1 ;system call number (sys_exit) | ||
mov ebx, 0 | ||
int 0x80 ;call kernel | ||
;==========================================================================================; | ||
|
||
section .data | ||
|
||
msg1 db 'Input string is : ' | ||
len1 equ $ -msg1 | ||
msg2 db 'Enter start index: ' | ||
len2 equ $ -msg2 | ||
msg3 db 'Enter end index: ' | ||
len3 equ $ -msg3 | ||
msg4 db 'Substring is: ' | ||
len4 equ $ -msg4 | ||
newline db " ",0xa | ||
newl_len equ $ -newline | ||
counter db '0' | ||
string_inp db "GoodMorning" | ||
string_len equ $ -string_inp | ||
print_temp db '0' | ||
len_temp db '0' | ||
|
||
;=============================================================================================; | ||
|
||
section .bss | ||
|
||
st_ind: resb 1 | ||
en_ind: resb 1 | ||
;==============================================================================================; |
Oops, something went wrong.