Created
September 2, 2024 06:24
-
-
Save mertbozkir/159043973f2d752c29a0a35c471520d7 to your computer and use it in GitHub Desktop.
prework
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
DATA DB 0.9, 2.7, 6.7, 11.5, 16.5, 20.6, 24.2, 24.3, 19.6, 13.9, 7.3, 2.8 | |
MOV CX,12 ; Set counter to 12 months | |
SUB BX,BX ; Clear BX, used as accumulator | |
MOV SI,OFFSET DATA ; Set up pointer | |
BACK: MOV AL,[SI] ; Move byte into AL | |
CBW ; Convert byte to word, add 1's to AH to extend AL to AX | |
ADD BX,AX ; Add to BX | |
INC SI ; Increment pointer | |
DEC CX ; Decrement counter | |
JNZ BACK ; Loop if not finished | |
MOV AX,BX ; Move result to AX | |
MOV CL,12 ; Set up for division by 12 | |
DIV CL ; Find the average |
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
.model small | |
.stack 100h | |
.data | |
message db 'INT example by Mert Bozkir 299860733', 0Dh, 0Ah | |
db '.. press any key to exit$' | |
- .code | |
main proc | |
mov ax, @data | |
mov ds, ax | |
- ; Calculate screen position for centered text | |
mov ah, 0Fh ; Get video mode | |
int 10h | |
mov al, 80 ; Assume 80 columns | |
sub al, 36 ; Message length (adjust if needed) | |
shr al, 1 ; Divide by 2 for center position | |
mov dl, al ; Column | |
mov dh, 12 ; Row (middle of 25 row screen) | |
- ; Set cursor position | |
mov ah, 02h | |
int 10h | |
- ; Display message | |
mov ah, 09h | |
lea dx, message | |
int 21h | |
- ; Wait for keypress | |
mov ah, 07h | |
int 21h | |
- ; Exit program | |
mov ah, 4Ch | |
int 21h | |
main endp | |
end main | |
#Flowchart | |
[Start] | |
| | |
v | |
[Initialize Data Segment] | |
| | |
v | |
[Clear Screen] | |
| | |
v | |
[Calculate Center Position] | |
| | |
v | |
[Set Cursor Position] | |
| | |
v | |
[Display Message] | |
| | |
v | |
[Wait for Keypress] | |
| | |
v | |
[Exit Program] | |
| | |
v | |
[End] |
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
.model small | |
.stack 100h | |
.data | |
msg1 db "Average calculator by Mert Bozkir 299860733", 0Dh, 0Ah | |
db "Enter single digit positive numbers (max 20) and enter 0 to terminate number entrance$" | |
msg2 db 0Dh, 0Ah, "The average is: $" | |
numbers db 20 dup(?) | |
sum dw 0 | |
count db 0 | |
- .code | |
main proc | |
mov ax, @data | |
mov ds, ax | |
- ; Clear screen | |
mov ax, 0003h | |
int 10h | |
- ; Set cursor position to middle of screen | |
mov ah, 02h | |
mov bh, 0 | |
mov dh, 12 | |
mov dl, 10 | |
int 10h | |
- ; Display initial message | |
mov ah, 09h | |
lea dx, msg1 | |
int 21h | |
- ; Input loop | |
mov si, 0 | |
input_loop: | |
; Read a character | |
mov ah, 01h | |
int 21h | |
- ; Check if it's '0' (terminate) | |
cmp al, '0' | |
je calculate_average | |
- ; Check if it's a valid digit (1-9) | |
cmp al, '1' | |
jb input_loop | |
cmp al, '9' | |
ja input_loop | |
- ; Store the digit | |
sub al, '0' | |
mov numbers[si], al | |
inc si | |
inc count | |
- ; Check if we've reached 20 numbers | |
cmp count, 20 | |
jae calculate_average | |
- jmp input_loop | |
- calculate_average: | |
; Clear screen | |
mov ax, 0003h | |
int 10h | |
- ; Calculate sum | |
mov cx, 0 | |
mov cl, count | |
mov si, 0 | |
mov ax, 0 | |
sum_loop: | |
movzx bx, numbers[si] | |
add ax, bx | |
inc si | |
loop sum_loop | |
- ; Calculate average | |
div count | |
; Display result | |
mov ah, 09h | |
lea dx, msg2 | |
int 21h | |
- ; Convert result to ASCII and display | |
add al, '0' | |
mov dl, al | |
mov ah, 02h | |
int 21h | |
- ; Exit program | |
mov ah, 4Ch | |
int 21h | |
main endp | |
end main |
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
.model small | |
.stack 100h | |
.data | |
message db 'MOUSE example by Mert Bozkir 299860733', 0Dh, 0Ah | |
db '.. press right button of the Mouse to exit$' | |
.code | |
main proc | |
mov ax, @data | |
mov ds, ax | |
; Set video mode (80x25 text) | |
mov ax, 0003h | |
int 10h | |
; Calculate center position | |
mov ah, 03h | |
mov bh, 0 | |
int 10h | |
mov al, 12 ; Rows to move down (25/2 - 1) | |
sub dh, al | |
mov dl, 20 ; Columns to move right (80/2 - message_length/2) | |
; Set cursor position | |
mov ah, 02h | |
mov bh, 0 | |
int 10h | |
; Display message | |
mov ah, 09h | |
lea dx, message | |
int 21h | |
; Initialize mouse | |
mov ax, 0000h | |
int 33h | |
; Show mouse cursor | |
mov ax, 0001h | |
int 33h | |
mouse_loop: | |
; Get mouse status | |
mov ax, 0003h | |
int 33h | |
; Check if right button is pressed (bx & 2) | |
test bx, 2 | |
jnz exit_program | |
; Small delay | |
mov cx, 0FFFFh | |
delay_loop: | |
loop delay_loop | |
jmp mouse_loop | |
exit_program: | |
; Hide mouse cursor | |
mov ax, 0002h | |
int 33h | |
; Exit program | |
mov ah, 4Ch | |
int 21h | |
main endp | |
end main |
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
.data | |
msg db 'Enter a word: $' | |
msg4 db 'WELCOME TO THE PALINDROME EXPERIMENT $' | |
msg5 db 'To check whether the letters from the first digit to the median digit of a word are identical to the letters from the last digit to the median digit (If the string is more than 30 letters, you will get an error message.): $' | |
msg1 db 'It is a Palindrome $' | |
msg2 db 'It is not a Palindrome $' | |
msg3 db 'Length is too long $' | |
buffer db 10,?, 10 dup('$') | |
.code | |
mov edx,offset msg4 ;Load the address of the "WELCOME TO THE PALINDROME EXPERIMENT" message into edx | |
mov ah,09h ;Set AH to 09h (invoke string printing service) | |
int 21h ;Call interrupt to print the message | |
mov edx,offset msg5 ;Load the address of the explanation message for palindrome check into edx | |
mov ah,09h ;Set AH to 09h (invoke string printing service) | |
int 21h ;Call interrupt to print the message | |
ank: | |
mov edx,offset msg ;Load the address of the message prompting for user input into edx | |
mov ah,09h ;Set AH to 09h (invoke string printing service) | |
int 21h ;Call interrupt to print the message | |
mov edx,offset buffer ;Load the address of buffer to edx to get user input | |
mov ah,0Ah ;Set AH to 0Ah (invoke buffered input service) | |
int 21h ;Call interrupt to get input from the user | |
mov edi,esi ;Copy the address of input from ESI to EDI | |
mov eax,[buffer] ;Get the length of input stored in buffer | |
dec eax ;Because an extra byte is stored in the buffer structure after the 0Ah call | |
add edi,eax ;Set EDI to point to the end of input | |
mov ebx,30 ;Load 30 which is the MAXIMUM Length into EBX | |
cmp ebx,eax ;Check if the length of input is less than 30 | |
jl print_msg3 ;If it's less than 30, jump to print_msg3 | |
check_palindrome: | |
mov eax,[esi] ;Get a character from the start address | |
mov ebx,[edi] ;Get a character from the end address | |
cmp eax,ebx ;Compare the characters | |
jne print_message2 ;If they are different, jump to print_message2 | |
inc esi ;Move the start address to the next character | |
dec edi ;Move the end address to the previous character | |
cmp edi,esi ;Check if there is an intersection between EDI and ESI | |
jl check_palindrome ;If there's no intersection, continue palindrome check | |
print_message: ;Print msg1 which is 'It is a Palindrome' | |
mov edx,offset msg1 | |
mov ah,09h | |
int 21h | |
jmp ank ;Jump to ank | |
print_message2: ;Print msg2 which is 'It is not a Palindrome' | |
mov edx,offset msg2 | |
mov ah,09h | |
int 21h | |
jmp ank ;Jump to ank | |
print_msg3: ;Print msg3 which is 'Length is too long' | |
mov edx,offset msg3 | |
mov ah,09h | |
int 21h | |
jmp exit ;Jump to ank | |
exit: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment