├── Project #0 - Classroom Grading ├── Project #0 - Classroom Grading.asm └── README.md ├── Project #1 - Car Waiting Meter ├── Project #1 - Car Waiting Meter.asm └── README.md ├── Project #2 - Packet Transmission Control ├── Project #2 - Packet Transmission Control.asm └── README.md ├── Project #3 - Security lock ├── README.md └── Security_lock.asm ├── Project #4 - Monoalphabetic Substitution Encryption ├── Project #4 (Monoalphabetic Substitution Encryption).asm └── README.md ├── Project #5 - Marathon Results ├── Project #5 - Marathon Results.asm └── README.md ├── Project #6 - Traffic Light Control ├── Project #6 - Traffic Light Control.asm └── README.md ├── Project #7 - Heater Alarm ├── Project #7 - Heater Alarm.asm └── README.md ├── Project #8 - ATM Machine ├── Project #8 - ATM Machine.asm └── README.md ├── Project #9 - Mononumeric substitution encryption ├── Project #9 - Mononumeric substitution encryption.asm └── README.md └── README.md /Project #0 - Classroom Grading/Project #0 - Classroom Grading.asm: -------------------------------------------------------------------------------- 1 | include 'emu8086.inc' 2 | 3 | JMP START 4 | 5 | DATA SEGMENT 6 | N DW ? 7 | MARKS DB 1000 DUP (?) ;1000 IS THE MAXIMYM NUMBER OF STUDENTS 8 | ID DB 1000 DUP (?) 9 | 10 | MSG1 DB 'Enter the number of students(DOES NOT EXCEED 1000): ',0 ;0 INDICATES THAT THE MESSAGE ENDS HERE 11 | MSG2 DB 0Dh,0Ah, 0Dh,0Ah,'Enter the IDs of students: ',0 ;0Dh,0Ah, 0Dh,0Ah MEANS NEW LINE AND RETURN CURSOR TO ITS BEGINNING ACCORDING TO ASCI CODES 12 | MSG3 DB 0Dh,0Ah, 0Dh,0Ah,'Enter the marks of students: ',0 13 | HR DB 0Dh,0Ah, 0Dh,0Ah,'*******************Sorted Marks***********************',0 ;HORIZONTAL ROW 14 | MSG4 DB 0Dh,0Ah, 0Dh,0Ah,'ID: ',09H,'MARKS:',0 15 | DATA ENDS 16 | 17 | CODE SEGMENT 18 | ASSUME DS:DATA CS:CODE 19 | 20 | ;SETTING DATA SEGMENT 21 | START: MOV AX, DATA 22 | MOV DS, AX 23 | 24 | ;DEFINING FUNCTIONS FOR THE LIBRARY EMU8086 WHICH WILL BE USED LATER 25 | DEFINE_SCAN_NUM 26 | DEFINE_PRINT_STRING 27 | DEFINE_PRINT_NUM 28 | DEFINE_PRINT_NUM_UNS 29 | 30 | 31 | ;READING NUMBER OF STUDENTS 32 | 33 | LEA SI,MSG1 ;PRINT_STRING FUNCTION PRINTS WHAT'S IN SI 34 | CALL PRINT_STRING 35 | CALL SCAN_NUM ;THE FUNCTION PUTS THE INPUT IN CX 36 | MOV N,CX 37 | 38 | 39 | 40 | ;READING IDs OF STUDENTS 41 | LEA SI,MSG2 42 | CALL PRINT_STRING 43 | MOV SI, 0 44 | 45 | LOOP1: CALL SCAN_NUM 46 | MOV ID[SI],CL 47 | INC SI 48 | PRINT 0AH ;PRINT NEW LINE 49 | PRINT 0DH ;RETURN CURSOR TO THE BEGINNING 50 | CMP SI,N 51 | JNE LOOP1 52 | 53 | 54 | 55 | ;READING MARKS OF STUDENTS 56 | LEA SI,MSG3 57 | CALL PRINT_STRING 58 | MOV SI, 0 59 | 60 | LOOP2: CALL SCAN_NUM 61 | MOV MARKS[SI],CL 62 | INC SI 63 | PRINT 0AH ;PRINT NEW LINE 64 | PRINT 0DH ;RETURN CURSOR TO THE BEGINNING 65 | CMP SI,N 66 | JNE LOOP2 67 | 68 | 69 | 70 | ;SORTING THEM ACCORDING TO MARKS USING BUBBLE SORT 71 | 72 | DEC N ;BECAUSE WE WON'T COMPARE THE LAST ELEMENT 73 | MOV CX, N ;CX AS I 74 | OUTER: MOV SI, 0 ;SI AS J 75 | 76 | 77 | INNER: MOV AL, MARKS[SI] 78 | MOV DL, ID[SI] 79 | INC SI 80 | CMP MARKS[SI], AL 81 | JB SKIP 82 | XCHG AL, MARKS[SI] 83 | MOV MARKS[SI-1], AL 84 | XCHG DL, ID[SI] 85 | MOV ID[SI-1], DL 86 | 87 | SKIP: CMP SI, CX 88 | JL INNER 89 | LOOP OUTER 90 | 91 | 92 | INC N ;WE INCREMENT N AGAIN BECAUSE WE DECREASED IT BEFORE 93 | 94 | 95 | ;PRINT TABLE OF THEIR IDs AND MARKS AFTER SORTING 96 | LEA SI,HR 97 | CALL PRINT_STRING 98 | LEA SI,MSG4 99 | CALL PRINT_STRING 100 | PRINT 0AH ;PRINT NEW LINE 101 | PRINT 0DH ;RETURN CURSORT TO THE BEGINNING 102 | 103 | MOV SI, 0 104 | LOOP3: MOV AX,0 105 | MOV AL,ID[SI] 106 | 107 | CALL PRINT_NUM_UNS 108 | PRINT 09H ;PRINT TAB 109 | MOV AL,MARKS[SI] 110 | CALL PRINT_NUM_UNS 111 | PRINT 0AH ;PRINT NEW LINE 112 | PRINT 0DH ;RETURN CURSORT TO THE BEGGINING 113 | INC SI 114 | CMP SI,N 115 | JNE LOOP3 116 | 117 | CODE ENDS 118 | 119 | END START 120 | 121 | 122 | ret 123 | 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /Project #0 - Classroom Grading/README.md: -------------------------------------------------------------------------------- 1 | # Classroom Grading EMU 8086 2 | ## Table of Content 3 | - [Classroom-Grading-emu-8086](#classroom-grading-emu-8086) 4 | * [Abstract](#abstract) 5 | * [Sample Run](#sample-run) 6 | * [Author](#author) 7 | 8 | ## Abstract 9 | An 8086 Assembly program to rearrange them in descending order according to their grades in any course. 10 | 11 | A classroom has 25 students. It is required to rearrange them in descending order according to their grades in the microprocessor course. 12 | 13 | The inputs are two tables. The first table contains the student number and the second one contains their grades. 14 | 15 | The outputs are two tables. The first one contains the student number arranged according to their grades and the second table shows these grades. 16 | 17 | > The program supports N students, not 25 particularly 18 | 19 | ## Sample Run 20 | ![image](https://user-images.githubusercontent.com/41492875/169708054-e9c15d5d-888c-45e1-9369-19b2b6cd6d70.png) 21 | 22 | ## Author 23 | [Yousef Kotp](https://github.com/yousefkotp) 24 | -------------------------------------------------------------------------------- /Project #1 - Car Waiting Meter/Project #1 - Car Waiting Meter.asm: -------------------------------------------------------------------------------- 1 | org 100h 2 | .data 3 | Entry db "Enter The Amount Of Paid Money or Enter '0' if you want to leave: $" 4 | 5 | wrongEntrymessage db "Not Specified value $" 6 | 7 | Expirymessage db "Expired... $ " 8 | 9 | 10 | .code 11 | 12 | mov ax,@data 13 | mov ds, ax ;load @data in data segement 14 | 15 | 16 | Userinput: 17 | 18 | 19 | ;Displaying Input Sentence By Calling Dos Interupt 21h list and choosing 09h which writes a string 20 | lea dx,Entry 21 | mov ah,09h 22 | int 21h 23 | 24 | mov dl,10 ;intialize by 10 25 | mov bl,0 ;intialize by 0 26 | 27 | scanNum: 28 | 29 | mov ah, 01h 30 | int 21h 31 | 32 | cmp al, 13 ; Terminates Loop if "ENTER KEY" 33 | je Return 34 | 35 | mov ah, 0 36 | sub al, 48 ; ASCII 37 | 38 | mov cl, al 39 | mov al, bl ; bl contains the previous value 40 | 41 | mul dl ; multiply the previous value with 10 42 | 43 | add al, cl ; previous * 10 + new value 44 | mov bl, al 45 | 46 | jmp scanNum 47 | 48 | Return: 49 | 50 | mov ax,0 51 | out 199,ax 52 | 53 | cmp bl, 1 ;int15h ah86 delays with micro seconds so if we need to delay 5 secs 54 | jne if5pounds ;we need actually 5000000 secs which can only be represented in 32bit-register 55 | mov cx, 4ch ; 5 sec ;so we use cx as upper 16 bit and dx as lower ones and then we intialize interupt handler 56 | mov dx, 4b40h 57 | jmp endif 58 | 59 | if5pounds: 60 | cmp bl, 5 61 | jne if10pounds 62 | mov cx, 1c9h ; 30 sec 63 | mov dx, 0c380h 64 | jmp endif 65 | 66 | if10pounds: 67 | cmp bl, 0Ah 68 | jne wrongentry 69 | mov cx, 393h ; 60 sec 70 | mov dx, 8700h 71 | jmp endif 72 | 73 | 74 | endif: 75 | 76 | ;Newline 77 | mov dx,13 78 | mov ah,2 79 | int 21h 80 | mov dx,10 81 | mov ah,2 82 | int 21h 83 | 84 | ;wait function 85 | mov ah,86h 86 | int 15h 87 | 88 | ;types Expired When Time is Finished 89 | lea dx,Expirymessage 90 | mov ah,09h 91 | int 21h 92 | mov ax,1 93 | out 199,ax 94 | 95 | jmp Final 96 | 97 | wrongentry: 98 | cmp bl,0h 99 | je END 100 | 101 | ;Newline 102 | mov dx,13 103 | mov ah,2 104 | int 21h 105 | mov dx,10 106 | mov ah,2 107 | int 21h 108 | 109 | lea dx,wrongEntrymessage 110 | mov ah,09h 111 | int 21h 112 | 113 | 114 | Final: 115 | 116 | ;Newline 117 | mov dx,13 118 | mov ah,2 119 | int 21h 120 | mov dx,10 121 | mov ah,2 122 | int 21h 123 | call Userinput 124 | 125 | END: 126 | hlt -------------------------------------------------------------------------------- /Project #1 - Car Waiting Meter/README.md: -------------------------------------------------------------------------------- 1 | # Car Waiting Meter 2 | ## Table of Content 3 | - [Car Waiting Meter](#car-waiting-meter) 4 | * [Abstract](#abstract) 5 | * [Author](#author) 6 | 7 | ## Abstract 8 | In the car parking, a car waiting meter is used. The driver puts a certain amount of money and 9 | this meter will allow him to park his car for a specific time. 10 | 11 | The price list is as follows: 12 | 13 | 1 pound → 5 sec, 5 pound → 30 sec, 10 pound → 60 sec. 14 | 15 | If the time is expired, a red led will turn on. 16 | 17 | The input is the amount of money. 18 | 19 | The output is LED turned red if time is expired. 20 | 21 | if the entry of the program is 0 the Program hlt "ENDS" Else one the specified inputs above the program delays for the specified time and the after delay ends "EXPIRED" is printed on the screen detecting that time has ended and led display return 0001 and then the program asks for the entry again if you want to stay longer by entering a new specified amount of money. 22 | 23 | You can see the output of the led display just by clicking on "VIRTUAL DEVICES" in the MENU BAR at the Run Window and Selecting "LED_DISPLAY". 24 | ## Author 25 | [Abdelrahman El Attar](https://github.com/abdelrahmanelattarr) 26 | -------------------------------------------------------------------------------- /Project #2 - Packet Transmission Control/Project #2 - Packet Transmission Control.asm: -------------------------------------------------------------------------------- 1 | INCLUDE "emu8086.inc" 2 | 3 | JMP START 4 | 5 | DATA SEGMENT 6 | PACKET DW 0 ;NUMBER OF PACKETS TO BE TRANSMITTED 7 | N DW 0 ;NUMBER OF TRANSMITTED PACKETS AND DETECT 128 CYCLE 8 | N2 DW 0 ;NUMBER OF TRANSMISSION 9 | MSG1 DW "Enter number of packets: ",0 10 | MSG2 DW "Number of Transmissions: ",0 11 | 12 | DATA ENDS 13 | 14 | CODE SEGMENT 15 | 16 | ASSUME DS:DATA CS:CODE 17 | 18 | START: 19 | MOV CX, DATA ;DECLARATION OF DATA SEGEMENT 20 | MOV DS, CX 21 | DEFINE_SCAN_NUM 22 | DEFINE_PRINT_STRING 23 | DEFINE_PRINT_NUM 24 | DEFINE_PRINT_NUM_UNS 25 | DEFINE_CLEAR_SCREEN 26 | 27 | LEA SI,MSG1 28 | CAll PRINT_STRING 29 | CALL SCAN_NUM 30 | MOV PACKET,CX 31 | 32 | 33 | LOOP1: INC N2 ;INCREASING NUMBER OF TRANSMISSOIN MADE 34 | INC N ;INCREASING NUMBER OF PACKETS TRANSMITTED 35 | DEC PACKET ;DECREASING NUMBER OF PACKETS TO BE TRANSMITTED 36 | JMP DONE 37 | 38 | LOOP2: CMP N,64 39 | JB FUNC1 ;IF NUMBER OF PACKETS TRANSMITTED IS LESS THAN 64 40 | 41 | loop_start: 42 | cmp N,128 ; compare loop counter with 10 43 | JGE loop_end ; jump out of loop if counter >= 10 44 | JMP LOOP1 45 | JMP loop_start ; jump back to the start of the loop 46 | loop_end: 47 | MOV N,0 48 | JMP LOOP1 49 | 50 | FUNC1: MOV CX,N 51 | CMP CX,PACKET ;CHECK IF NUMBER OF LEFT TO BE TRANSMITTED IS SMALLER THAN TRANSFERRED PACKETS AT THAT TIME 52 | JAE BREAK 53 | SHL N,1 54 | SUB PACKET,CX 55 | INC N2 56 | 57 | DONE: CMP PACKET,0 58 | JBE BREAK 59 | CMP N,64 60 | JB FUNC1 ;IF NUMBER OF PACKETS TRANSMITTED IS LESS THAN 64 61 | JMP loop_start 62 | 63 | BREAK: 64 | PRINT 0AH 65 | PRINT 0DH 66 | LEA SI,MSG2 67 | CALL PRINT_STRING 68 | MOV AX,N2 69 | CALL PRINT_NUM_UNS 70 | 71 | 72 | CODE ENDS 73 | 74 | END START 75 | 76 | ret -------------------------------------------------------------------------------- /Project #2 - Packet Transmission Control/README.md: -------------------------------------------------------------------------------- 1 | # Packet Transmission Control EMU 8086 2 | ## Table of Content 3 | - [Classroom-Grading-emu-8086](#classroom-grading-emu-8086) 4 | * [Abstract](#abstract) 5 | * [Sample Run](#sample-run) 6 | * [Author](#author) 7 | 8 | ## Abstract 9 | Consider the maximum capacity of a network is 128 packets. The user starts his packets 10 | transmission by 1 packet. Then he/she increases the number of packets according to the 11 | following rules: 12 | 13 | If the number of transmitted packets < 64 packets, the number will be doubled. 14 | 15 | If the number of transmitted packets ≥ 64 packets, the number will be increased by 1. 16 | 17 | If the number of transmitted packets = 128 packets, the user will start over and transmit 1 18 | packets and repeat the previous rules. 19 | 20 | The input is the size of the transmitted file. 21 | 22 | The output is the number of Transmissions used to transmit this file. 23 | ## Sample Run 24 | ![image](https://user-images.githubusercontent.com/41492875/169708314-d157b7f6-33ce-42ef-b29c-c65ccb7afdf7.png) 25 | 26 | ## Author 27 | [Yousef Kotp](https://github.com/yousefkotp) 28 | -------------------------------------------------------------------------------- /Project #3 - Security lock/README.md: -------------------------------------------------------------------------------- 1 | # x86-Assembly-Monoalphabetic-Substitution-Encryption-System 2 | Monoalphabetic encryption/decryption system written in 8086 assembly language 3 | 4 | ## Table of Content 5 | - [8086-Assembly-Monoalphabetic-Substitution-Encryption-System](#x86-assembly-monoalphabetic-substitution-encryption-system) 6 | * [Abstract](#abstract) 7 | * [Author](#author) 8 | 9 | 10 | ## Abstract 11 | In the bank, a security lock is used to access some rooms. This lock accepts two inputs: the 12 | employee identification number (16 bits) and his/her password (4 bits). If the bank has 20 13 | employees, construct their database and store it in the memory. Then write a program to 14 | access these rooms. 15 | The inputs of the program are the employee identification and the password. 16 | The output is one bit (0/1) that means (denied/allowed). 17 | 18 | 19 | ## Author 20 | [Ahmad Hazem](https://github.com/AhmadHazem) 21 | 22 | 23 | -------------------------------------------------------------------------------- /Project #3 - Security lock/Security_lock.asm: -------------------------------------------------------------------------------- 1 | 2 | ; You may customize this and other start-up templates; 3 | ; The location of this template is c:\emu8086\inc\0_com_template.txt 4 | include emu8086.inc 5 | .MODEL SMALL 6 | .DATA 7 | ;I DB 0d 8 | SIZE EQU 10 9 | HEAD DB '________________Security lock________________','$' 10 | MSG1 DB 13, 10, 'Enter your ID:$' 11 | MSG2 DB 13, 10, 'Enter your Password:$' 12 | MSG3 DB 13, 10, 'ERROR ID not Found!$' 13 | MSG4 DB 13, 10, 'Wrong Password! Access denied$' 14 | MSG5 DB 13, 10, 'Correct! Welocome to the Safe$' 15 | MSG6 DB 13, 10, 'Too Long password!$' 16 | TEMP_ID DW 1 DUP(?),0 17 | TEMP_Pass DB 1 DUP(?) 18 | IDSize = $-TEMP_ID 19 | PassSize = $-Temp_Pass 20 | ID DW 'A150', 'B255', 'CE20', 'BB71', 'D111', 'E500', 'F432', 'EC12', '5321', '9876' 21 | Password DB 1, 2, 3, 4, 7, 10, 11, 13, 12, 14 22 | 23 | .CODE 24 | MAIN PROC 25 | MOV AX,@DATA ;In 26 | MOV DS,AX 27 | MOV AX,0000H 28 | 29 | 30 | Title: LEA DX,HEAD 31 | MOV AH,09H 32 | INT 21H 33 | 34 | ID_PROMPT: LEA DX,MSG1 35 | MOV AH,09H 36 | INT 21H 37 | 38 | 39 | ID_INPUT: MOV BX,0 40 | MOV DX,0 41 | LEA DI,TEMP_ID 42 | MOV DX,IDSize 43 | CALL get_string 44 | 45 | 46 | CheckID: MOV BL,0 47 | MOV SI,0 48 | 49 | AGAIN: MOV AX,ID[SI] 50 | MOV DX,TEMP_ID 51 | CMP DX,AX 52 | JE PASS_PROMPT 53 | INC BL 54 | ADD SI,4 55 | CMP BL,SIZE 56 | JB AGAIN 57 | 58 | ERRORMSG: LEA DX,MSG3 59 | MOV AH,09H 60 | INT 21H 61 | JMP ID_PROMPT 62 | 63 | 64 | PASS_PROMPT:LEA DX,MSG2 65 | MOV AH,09H 66 | INT 21H 67 | 68 | Pass_INPUT: CALL scan_num 69 | CMP CL,0FH 70 | JAE TooLong 71 | MOV BH,00H 72 | MOV DL,Password[BX] 73 | CMP CL,DL 74 | JE CORRECT 75 | 76 | 77 | INCORRECT: LEA DX,MSG4 78 | MOV AH,09H 79 | INT 21H 80 | JMP ID_PROMPT 81 | 82 | CORRECT: LEA DX,MSG5 83 | MOV AH,09H 84 | INT 21H 85 | JMP Terminate 86 | 87 | TooLong: LEA DX,MSG6 88 | MOV AH,09H 89 | INT 21H 90 | JMP PASS_PROMPT 91 | 92 | 93 | DEFINE_SCAN_NUM 94 | DEFINE_GET_STRING 95 | Terminate: 96 | END MAIN 97 | 98 | 99 | -------------------------------------------------------------------------------- /Project #4 - Monoalphabetic Substitution Encryption/Project #4 (Monoalphabetic Substitution Encryption).asm: -------------------------------------------------------------------------------- 1 | 2 | ORG 0100H 3 | 4 | JMP start 5 | 6 | newline EQU 0AH ; \n 7 | cret EQU 0DH ; \r 8 | bcksp EQU 08H ; \b 9 | 10 | 11 | ; 12 | ; Hard-coded string: 13 | ; 14 | hardcoded_string DB 'Oh hi there! This is an encrypted message', cret, newline, '$' 15 | 16 | 17 | input_string DB 259 dup ('$') ; Reserved area for input string (256 chars + \r + \n + $) 18 | 19 | 20 | ; 21 | ; Messages and dialogues to be displayed in the UI: 22 | ; 23 | message_welcome DB newline, 'Welcome to the monoalphabetic encryption system! ', cret, newline 24 | DB 'Please choose how you wish to proceed:', cret, newline 25 | DB '1- Enter string as input (max: 256 chars)', cret, newline 26 | DB '2- Use hard-coded string', cret, newline, '$' 27 | 28 | message_using_hc DB '===============================', cret, newline 29 | DB 'USING YOUR HARDCODED STRING' , cret, newline 30 | DB '===============================', cret, newline, '$' 31 | 32 | message_using_input DB '===============================', cret, newline 33 | DB 'Please enter your string below' , cret, newline 34 | DB '===============================', cret, newline, '$' 35 | 36 | message_try_again DB cret, newline, 'Give it one more try? (y/n)', cret, newline, '$' 37 | 38 | message_press_key DB 'Press any key to exit...$' 39 | 40 | message_display_org DB cret, newline, 'Your original string: $' 41 | message_display_enc DB cret, 'Encrypted message: $' 42 | message_display_dec DB cret, 'Decrypted message: $' 43 | message_encrypting DB 'Encrypting...$' 44 | message_decrypting DB 'Decrypting...$' 45 | 46 | 47 | 48 | ; Just for reference ---------------------> 'abcdefghijklmnopqrstuvwxyz' 49 | encryption_table_lower DB 97 dup (' '), 'qwertyuiopasdfghjklzxcvbnm' 50 | decryption_table_lower DB 97 dup (' '), 'kxvmcnophqrszyijadlegwbuft' 51 | ; We leave 97(61H) blank spaces before the start of the table 52 | ; as the ASCII value of 'a' = 61H 53 | 54 | encryption_table_upper DB 65 dup (' '), 'QWERTYUIOPASDFGHJKLZXCVBNM' 55 | decryption_table_upper DB 65 dup (' '), 'KXVMCNOPHQRSZYIJADLEGWBUFT' 56 | ; We leave 65(41H) blank spaces before the start of the table 57 | ; as the ASCII value of 'A' = 41H 58 | 59 | 60 | start: 61 | 62 | LEA DX, message_welcome 63 | MOV AH, 09 64 | INT 21H 65 | MOV AH, 0 66 | INT 16H 67 | CMP AL, '2' ; User chose to use the hardcoded string 68 | JE use_hc 69 | CMP AL, '1' ; User chose to enter a string 70 | JNE start 71 | CALL get_input 72 | JMP start_process 73 | 74 | use_hc: LEA DX, message_using_hc 75 | MOV AH, 09 76 | INT 21H 77 | LEA SI, hardcoded_string 78 | 79 | 80 | start_process: 81 | 82 | ; Display original string 83 | LEA DX, message_display_org 84 | MOV AH, 09 ; value of AH is adjusted as operation of int 21H depends on its value 85 | INT 21H ; at AH = 09, int 21H outputs string at DS:DX 86 | LEA DX, SI 87 | MOV AH, 09 88 | INT 21H 89 | 90 | 91 | ; Encrypt: 92 | LEA DX, message_encrypting ; Display message 93 | MOV AH, 09 94 | INT 21H 95 | MOV AH, 1 ; value of AH is adjusted as operation of encrypt_decrypt depends on its value 96 | CALL encrypt_decrypt ; AH = 1 means monoalphabetic encryption, 0 means monoalphabetic decryption, else do nothing 97 | 98 | ; Display result on the screen: 99 | LEA DX, message_display_enc 100 | MOV AH, 09 ; value of AH is adjusted as operation of int 21H depends on its value 101 | INT 21H ; at AH = 09, int 21H outputs string at DS:DX 102 | LEA DX, SI 103 | MOV AH, 09 104 | INT 21H 105 | 106 | ; Decrypt: 107 | LEA DX, message_decrypting ; Display message 108 | MOV AH, 09 109 | INT 21H 110 | MOV AH, 0 ; AH = 0 means monoalphabetic decryption 111 | CALL encrypt_decrypt 112 | 113 | ; Display result on the screen: 114 | LEA DX, message_display_dec 115 | MOV AH, 09 ; value of AH is adjusted as operation of int 21H depends on its value 116 | INT 21H ; at AH = 09, int 21H outputs string at DS:DX 117 | LEA DX, SI 118 | MOV AH, 09 119 | INT 21H 120 | 121 | ;Display try again dialogue 122 | try_again: LEA DX, message_try_again 123 | MOV AH, 09 124 | INT 21H 125 | MOV AH, 0 126 | INT 16H 127 | CMP AL, 'y' 128 | JE start 129 | CMP AL, 'n' 130 | JNE try_again 131 | 132 | 133 | ; Wait for any key... 134 | LEA DX, message_press_key 135 | MOV AH, 09 136 | INT 21H 137 | MOV AH, 0 ; value of AH is adjusted as operation of int 16H depends on its value 138 | INT 16H ; at AH = 00, int 16H waits for keystroke from the keyboard (no echo) 139 | 140 | RET 141 | 142 | 143 | ; si - address of string to encrypt 144 | encrypt_decrypt PROC NEAR 145 | PUSH SI 146 | next_char: MOV AL, [SI] 147 | CMP AL, '$' ; End of string? 148 | JE end_of_string 149 | 150 | CMP AL, ' ' ;<--- Beginning of space check 151 | JNE cont ; Since this was a college assignment, One of my requirements was to omit spaces in my result so 152 | CALL omit_space ; you can just remove these 4 lines and the omit_space subroutine if you do not wish to do that. 153 | JMP next_char ;<--- End of space check 154 | 155 | cont: CALL enc_dec_char 156 | INC SI 157 | JMP next_char 158 | end_of_string: POP SI 159 | RET 160 | encrypt_decrypt ENDP 161 | 162 | 163 | 164 | ; 165 | ; Subroutine to send space to the end of the string (after '$') 166 | ; You can delete this subroutine if you do not need it 167 | ; 168 | omit_space PROC NEAR 169 | PUSH SI ; The reason I send the space after the '$' 170 | ; is to handle several consecutive spaces without 171 | omit_space_loop: MOV AL, [SI+1] ; entering an inifnite loop as opposed to just swapping 172 | MOV [SI+1], ' ' ; the ' ' character with the character after it 173 | MOV [SI], AL 174 | INC SI 175 | CMP [SI-1], '$' 176 | JNE omit_space_loop 177 | POP SI 178 | RET 179 | omit_space ENDP 180 | 181 | 182 | 183 | ; Subroutine to convert character with the 184 | ; appropriate table (encrypt/decrypt)(uppercase/lowercase) 185 | enc_dec_char PROC NEAR 186 | PUSH BX 187 | CMP AL, 'a' 188 | JB check_upper_char 189 | CMP AL, 'z' 190 | JA skip_char 191 | CMP AH, 1 ; AH = 1 means monoalphabetic encryption, since we are working with lower case, we use encryption_table_lower 192 | JE encrypt_lower_char 193 | CMP AH, 0 ; AH = 0 means monoalphabetic decryption, since we are working with lower case, we use decryption_table_lower 194 | JNE skip_char 195 | LEA BX, decryption_table_lower 196 | JMP translate_char 197 | encrypt_lower_char: LEA BX, encryption_table_lower 198 | JMP translate_char 199 | check_upper_char: CMP AL, 'A' 200 | JB skip_char 201 | CMP AL, 'Z' 202 | JA skip_char 203 | CMP AH, 1 ; AH = 1 means monoalphabetic encryption, since we are working with upper case, we use encryption_table_upper 204 | JE encrypt_upper_char 205 | CMP AH, 0 ; AH = 0 means monoalphabetic decryption, since we are working with upper case, we use decryption_table_upper 206 | JNE skip_char 207 | LEA BX, decryption_table_upper 208 | JMP translate_char 209 | encrypt_upper_char: LEA BX, encryption_table_upper 210 | translate_char: XLATB 211 | MOV [SI], AL 212 | skip_char: POP BX 213 | RET 214 | enc_dec_char ENDP 215 | 216 | 217 | 218 | ; Subroutine to take input string from the user 219 | ; The subroutine handles if the user presses backspace: delete char + inc CX 220 | ; The subroutine allows the user to enter a maximum of 256 chars 221 | get_input PROC NEAR 222 | LEA DX, message_using_input 223 | MOV AH, 09 224 | INT 21H 225 | LEA SI, input_string 226 | MOV AH, 1 227 | MOV CX, 255 ; To set a cap for string input to 256 chars 228 | JMP input_loop 229 | backspace_entered: INC CX ; Increment CX in case user presses backspace as a character is deleted 230 | input_loop: INT 21H 231 | MOV [SI], AL 232 | CMP AL, bcksp 233 | JNE cont_input 234 | CMP SI, offset input_string 235 | JE input_loop ;If the string is empty just loop again without affecting SI and without incrementing CX 236 | MOV [SI], ' ' 237 | CALL omit_space 238 | DEC SI 239 | JMP backspace_entered 240 | cont_input: INC SI 241 | CMP AL, cret 242 | JE terminate_string 243 | LOOP input_loop ; LOOP instead of JMP to incorporate (CX != 0000H) as a jump condition 244 | terminate_string: MOV [SI-1], cret 245 | MOV [SI], newline 246 | MOV [SI+1], '$' 247 | LEA SI, input_string 248 | RET 249 | get_input ENDP 250 | 251 | end 252 | -------------------------------------------------------------------------------- /Project #4 - Monoalphabetic Substitution Encryption/README.md: -------------------------------------------------------------------------------- 1 | # x86-Assembly-Monoalphabetic-Substitution-Encryption-System 2 | Monoalphabetic encryption/decryption system written in 8086 assembly language 3 | 4 | ## Table of Content 5 | - [8086-Assembly-Monoalphabetic-Substitution-Encryption-System](#x86-assembly-monoalphabetic-substitution-encryption-system) 6 | * [Abstract](#abstract) 7 | * [Functionality](#functionality) 8 | * [Tools](#tools) 9 | * [Remarks](#remarks) 10 | * [Author](#author) 11 | * [Sample Run Using emu8086](#sample-run) 12 | 13 | 14 | ## Abstract 15 | Encryption can be done in various ways. One of the simplest methods is [**monoalphabetic cipher**](https://www.101computing.net/mono-alphabetic-substitution-cipher/). A monoalphabetic cipher is a substitution cipher where each letter of the plain text is replaced with another letter of the alphabet. It uses a fixed key which consist of the 26 letters of a “shuffled alphabet”. 16 | 17 | This program implements this method to encrypt/decrypt a string of characters. 18 | 19 | ## Functionality 20 | **1. This program uses the following table as the reference for character substitution** 21 | ![table](https://user-images.githubusercontent.com/90573502/168689119-19c527fd-0ec6-4235-9358-ff8b50976086.jpg) 22 | 23 | **2. The program handles lowercase and uppercase characters** 24 | 25 | **3. This program omits all spaces in the result, however, I've clearly indicated the location of the part that does that in the code with comments so you can remove it at will.** 26 | 27 | ## Tools 28 | 1. emu8086 (IDE) 29 | 2. x86 Assembly 30 | 31 | ## Remarks 32 | This assembly program was run and tested on the x86 emulator [emu8086](https://emu8086.en.lo4d.com/windows#:~:text=Tutorial....-,Emu8086%20is%20a%20Microprocessor%20Emulator%20with%20an%20integrated%208086%20Assembler,memory%20and%20input%2Foutput%20devices.). 33 | 34 | ## Author 35 | [Adham Mohamed](https://github.com/adhammohamed1) 36 | 37 | ## Sample Run Using emu8086: 38 | 39 | **The program lets the user choose whether to enter a string or use the hard-coded one** 40 | 41 | This is the harcoded string: 42 | ![harcoded-string](https://user-images.githubusercontent.com/90573502/169605022-c2afbaba-cc8a-4a95-9a01-2f73ba2f491a.jpg) 43 | 44 | 45 | **Main Menu** 46 | ![mainmenu](https://user-images.githubusercontent.com/90573502/169605037-9e5f0e06-e05c-4159-93fe-a56eb1b86fca.jpg) 47 | 48 | 49 | **Entered '2' to use the hard-coded string** 50 | ![used-hardcoded](https://user-images.githubusercontent.com/90573502/169605063-d87085b4-c512-4dbb-aff2-af0a08ee338b.jpg) 51 | 52 | 53 | **And done!** 54 | ![done-hardcoded](https://user-images.githubusercontent.com/90573502/169605079-7d2059ff-8184-49fe-819d-c3fb442dfd00.jpg) 55 | 56 | 57 | **Entered 'y' to try again and '1' to input string** 58 | ![entering-input](https://user-images.githubusercontent.com/90573502/169605105-d9c69581-2fa4-4120-83b9-036d9e25edc9.jpg) 59 | 60 | 61 | **Processing the given string** 62 | ![used-input](https://user-images.githubusercontent.com/90573502/169605121-7b83a252-f8fb-46ec-bc4c-93f0e57608aa.jpg) 63 | 64 | 65 | **And done!** 66 | ![done](https://user-images.githubusercontent.com/90573502/169605129-8e9ad35b-9311-4823-bac2-cab9e9f3a6bf.jpg) 67 | 68 | -------------------------------------------------------------------------------- /Project #5 - Marathon Results/Project #5 - Marathon Results.asm: -------------------------------------------------------------------------------- 1 | include 'emu8086.inc' 2 | 3 | JMP START 4 | 5 | DATA SEGMENT 6 | N DW 25 7 | NUMBERS DB 25 DUP (?) 8 | TIME DB 25 DUP (?) 9 | MSG1 DB 'Enter the numbers of players: ',0 10 | MSG2 DB 0DH,0AH,'Enter the time of players: ',0 11 | MSG3 DB 0DH,0AH,'Times after sorting: ',0AH,0DH,0 12 | 13 | DATA ENDS 14 | 15 | CODE SEGMENT 16 | 17 | ASSUME DS:DATA CS:CODE 18 | START: MOV AX, DATA 19 | MOV DS, AX 20 | 21 | DEFINE_SCAN_NUM 22 | DEFINE_PRINT_STRING 23 | DEFINE_PRINT_NUM 24 | DEFINE_PRINT_NUM_UNS 25 | 26 | 27 | LEA SI,MSG1 28 | CALL PRINT_STRING 29 | MOV SI, 0 30 | 31 | LOOP1: CALL SCAN_NUM 32 | MOV NUMBERS[SI],CL 33 | INC SI 34 | PRINT 0AH 35 | PRINT 0DH 36 | CMP SI,N 37 | JNE LOOP1 38 | 39 | 40 | 41 | LEA SI,MSG2 42 | CALL PRINT_STRING 43 | MOV SI, 0 44 | 45 | LOOP2: CALL SCAN_NUM 46 | MOV TIME[SI],CL 47 | INC SI 48 | PRINT 0AH 49 | PRINT 0DH 50 | CMP SI,N 51 | JNE LOOP2 52 | 53 | 54 | 55 | ;SORTING 56 | DEC N 57 | MOV CX, N 58 | OUTER: MOV SI, 0 59 | 60 | 61 | INNER: MOV AL, TIME[SI] 62 | MOV DL, NUMBERS[SI] 63 | INC SI 64 | CMP TIME[SI], AL 65 | JA SKIP 66 | XCHG AL, TIME[SI] 67 | MOV TIME[SI-1], AL 68 | XCHG DL, NUMBERS[SI] 69 | MOV NUMBERS[SI-1], DL 70 | 71 | SKIP: CMP SI, CX 72 | JL INNER 73 | LOOP OUTER 74 | 75 | INC N 76 | 77 | LEA SI,MSG3 78 | CALL PRINT_STRING 79 | MOV SI, 0 80 | MOV AH,0 81 | 82 | LOOP3: MOV AL,NUMBERS[SI] 83 | CALL PRINT_NUM_UNS 84 | PRINT 09H 85 | MOV AL,TIME[SI] 86 | CALL PRINT_NUM_UNS 87 | PRINT 0AH 88 | PRINT 0DH 89 | INC SI 90 | CMP SI,N 91 | JNE LOOP3 92 | 93 | CODE ENDS 94 | 95 | END START 96 | 97 | 98 | ret 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /Project #5 - Marathon Results/README.md: -------------------------------------------------------------------------------- 1 | # Marathon Results EMU 8086 2 | 3 | ## Table of Content 4 | - [Classroom-Grading-emu-8086](#classroom-grading-emu-8086) 5 | * [Abstract](#abstract) 6 | * [Sample Run](#sample-run) 7 | * [Author](#author) 8 | ## Abstract 9 | 25 players are participated in a marathon. Their numbers and time in which they completed 10 | the marathon are stored in the memory. It is required to rearrange them in ascending order to 11 | find the winner. 12 | 13 | The inputs are two tables. The first table contains the player number and the second one 14 | contains their recorded time. 15 | 16 | The outputs are two tables. The first one contains the player number arranged according to 17 | their times and the second table shows these times. 18 | ## Sample Run 19 | ![image](https://user-images.githubusercontent.com/41492875/169708235-3741167d-86f9-4ec8-8f32-7c8990d7c3f3.png) 20 | 21 | ## Author 22 | [Yousef Kotp](https://github.com/yousefkotp) 23 | -------------------------------------------------------------------------------- /Project #6 - Traffic Light Control/Project #6 - Traffic Light Control.asm: -------------------------------------------------------------------------------- 1 | #start=Traffic_Lights.exe# 2 | ;Red is the least significant of each consecutive 3 bits : 0,3,6,9 3 | ;Yellow is the middle significant of each 3 consecutive bits: 1,4,7,A 4 | ;Green is the most significant of each 3 consecutive bits: 2,5,8,B 5 | ;the last 4 bits are unused C,D,E,F 6 | 7 | name "traffic" 8 | mov ax, 249h ; 249h means all are red 0,3,6,9 bits are all ones 9 | out 4, ax ;4 is the output number for the traffic (built-in) 10 | 11 | ; wait 5 seconds for the initial movement 12 | mov cx, 4Ch ; 004C4B40h = 5,000,000 micro seconds calculated by calculator from decimal to hexa 13 | mov dx, 4B40h 14 | mov ah, 86h ;ah is loaded with 86 (maps to interrupt 15 so it's constant) is needed for interrupt 15 15 | int 15h ;intterupt 15 checks cx:dx and is used to delay 16 | 17 | 18 | 19 | lop: 20 | mov ax, transition1 ;1st iteration 21 | out 4, ax 22 | 23 | ; wait 120 seconds (120 million microseconds) 24 | ;mov cx, 0727h ; 07270E00H=120 million microseconds, 120 not 180 because we will need yellow to be active for 60 seconds (red and greed active with yellow so total for red and green is 180 seconds) 25 | ;mov dx, 0E00h 26 | ;mov ah, 86h 27 | ;int 15h 28 | ;THIS CODE SHOULD CAUSE DELAY 2 MINS BUT IT ONLY CAUSES 1 MIN FOR SOME REASON so I delayed 60 secs twice 29 | ; wait 60 seconds (60 million microseconds) 30 | mov cx, 0393h ; 03938700H=60 million microseconds 31 | mov dx, 8700h 32 | mov ah, 86h 33 | int 15h 34 | ; wait 60 seconds (60 million microseconds) 35 | mov cx, 0393h ; 03938700H=60 million microseconds 36 | mov dx, 8700h 37 | mov ah, 86h 38 | int 15h 39 | 40 | 41 | mov ax,transition2 ;2nd iteration 42 | out 4,ax 43 | 44 | 45 | ; wait 60 seconds (60 million microseconds) 46 | mov cx, 0393h ; 03938700H=60 million microseconds 47 | mov dx, 8700h 48 | mov ah, 86h 49 | int 15h 50 | 51 | 52 | ;mov ax, 249h ; 249h means all are red 0,3,6,9 bits are all ones 53 | ;out 4, ax ;4 is the output number for the traffic (built-in) 54 | 55 | ; wait 5 seconds for the initial movement 56 | ;mov cx, 4Ch ; 004C4B40h = 5,000,000 micro seconds calculated by calculator from decimal to hexa 57 | ;mov dx, 4B40h 58 | ;mov ah, 86h ;ah is loaded with 86 (maps to interrupt 15 so it's constant) is needed for interrupt 15 59 | ;int 15h ;intterupt 15 checks cx:dx and is used to delay 60 | 61 | mov ax, transition3 ;3rd iteration 62 | out 4, ax 63 | 64 | ; wait 60 seconds (60 million microseconds) 65 | mov cx, 0393h ; 03938700H=60 million microseconds 66 | mov dx, 8700h 67 | mov ah, 86h 68 | int 15h 69 | ; wait 60 seconds (60 million microseconds) 70 | mov cx, 0393h ; 03938700H=60 million microseconds 71 | mov dx, 8700h 72 | mov ah, 86h 73 | int 15h 74 | 75 | mov ax,transition4 ;4th iteration 76 | out 4,ax 77 | 78 | ; wait 60 seconds 79 | mov cx, 0393h 80 | mov dx, 8700h 81 | mov ah, 86h 82 | int 15h 83 | 84 | mov ax, 249h ; 249h means all are red 0,3,6,9 bits are all ones 85 | out 4, ax ;4 is the output number for the traffic (built-in) 86 | 87 | ; wait 5 seconds for the initial movement 88 | mov cx, 4Ch ; 004C4B40h = 5,000,000 micro seconds calculated by calculator from decimal to hexa 89 | mov dx, 4B40h 90 | mov ah, 86h ;ah is loaded with 86 (maps to interrupt 15 so it's constant) is needed for interrupt 15 91 | int 15h ;intterupt 15 checks cx:dx and is used to delay 92 | 93 | 94 | jmp lop 95 | 96 | ; FEDC_BA98_7654_3210 97 | transition1 equ 0000_0011_0000_1100b ;2 Red and 2 Green(north and south are green) 98 | transition2 equ 0000_0111_1001_1110b ;all 4 are Yellow (two will begin to move soon and two will stop moving soon) and the red and green remain) 99 | transition3 equ 0000_1000_0110_0001b ;2 Red and 2 Green(east and west are green) 100 | transition4 equ 0000_1100_1111_0011b ;all 4 are Yellow (two will begin to move soon and two will stop moving soon) and the red and green remain) -------------------------------------------------------------------------------- /Project #6 - Traffic Light Control/README.md: -------------------------------------------------------------------------------- 1 | # Traffic Light Control 2 | ## Table of Content 3 | - [Traffic Light Control](#traffic-light-control) 4 | * [Abstract](#abstract) 5 | * [Author](#author) 6 | 7 | ## Abstract 8 | Write a program to control the time of the traffic lights. The red and green signals should be 9 | on for 3 minutes. The yellow signal should be on for 1 minute. 10 | ## Author 11 | [Mohammed El Battawty](https://github.com/MohamedBattawy) 12 | -------------------------------------------------------------------------------- /Project #7 - Heater Alarm/Project #7 - Heater Alarm.asm: -------------------------------------------------------------------------------- 1 | JMP DONE ;jump to done 2 | 3 | LOW: PRINT 'GREEN LED IS TURNED ON' ;Prints an indication message 4 | JMP DONE ;jump to done 5 | 6 | HIGH: PRINT 'RED LED IS TURNED ON' ;Prints an indication message 7 | 8 | DONE: PRINTN 9 | PRINT '-----------------------------------------------------' 10 | PRINTN 11 | PRINT 'Another Reading in 3 minutes Please Wait' 12 | PRINTN 13 | CALL DELAY3MIN ;calls the delay function 14 | JMP START ;jumps to start 15 | 16 | RET ;Returns to the main caller (Operating System) 17 | 18 | 19 | DELAY3MIN PROC ;Procedure for the 3 minutes delay 20 | 21 | MOV AL, 3 ;Loop Counter 22 | ;The resolution of the wait period is in microseconds (60 million microseconds --> 1 minute) equivalent to 03938700H 23 | REPEAT: MOV CX, 0393H ;Upper two bytes (0393H) 24 | MOV DX, 8700H ;Lower two bytes (8700H) 25 | MOV AH, 86H ;Auxulary Register with 86H for INT 15H 26 | INT 15H ;BIOS wait function, Inputs are CX:DX, waits for a specific number of microseconds before returning control to caller 27 | DEC AL ;Decrement AL 28 | JNZ REPEAT ;Loop 3 times to generate 3 minutes delay 29 | 30 | RET ;Returns to the caller 31 | 32 | DELAY3MIN ENDP 33 | 34 | 35 | DEFINE_SCAN_NUM ;A macro that scan input from user defined before end 36 | END ;Stop the Program -------------------------------------------------------------------------------- /Project #7 - Heater Alarm/README.md: -------------------------------------------------------------------------------- 1 | # Heater Alarm 2 | ## Table of Content 3 | - [Heater Alarm](#heater-alarm) 4 | * [Abstract](#abstract) 5 | * [Author](#author) 6 | 7 | ## Abstract 8 | Consider a boiler in a petrochemical factory. Its temperature is measured every 3 minutes. 9 | If the temperature <= 200ºC, a green led will turn on. 10 | 11 | If the 200 < temperature < 500ºC, a yellow led will turn on. 12 | 13 | If the temperature >= 500ºC, a red led will turn on. 14 | 15 | Write a program that reads the temperature every 3 minutes and shows the LED condition. 16 | 17 | 18 | ## Author 19 | * Yousef Walid 20 | -------------------------------------------------------------------------------- /Project #8 - ATM Machine/Project #8 - ATM Machine.asm: -------------------------------------------------------------------------------- 1 | include 'emu8086.inc' 2 | JMP START 3 | 4 | DATA SEGMENT 5 | TOTAL DW 20 6 | IDS1 DW 0000H,0001H,0002H,0003H,0004H,0005H,0006H,0007H,0008H,0009H 7 | IDS2 DW 000AH,000BH,000CH,000DH,000EH,000FH,0010H,0011H,0012H,0013H 8 | PASSWORDS1 DB 00H, 01H, 02H, 03H, 04H, 05H, 06H, 07H, 08H, 09H 9 | PASSWORDS2 DB 0AH, 0BH, 0CH, 0DH, 0EH, 0FH, 01H, 02H, 03H, 04H 10 | DATA1 DB '******WELCOME*******',0 11 | DATA2 DB 0DH,0AH,'ENTER YOUR ID: ',0 12 | DATA3 DB 0DH,0AH,'ENTER YOUR PASSWORD: ',0 13 | DATA4 DB 0DH,0AH,'DENIED 0 ',0 14 | DATA5 DB 0DH,0AH,'ALLOWED 1 ',0 15 | DATA6 DB '******WELCOME BACK*******',0 16 | IDINPUT DW 1 DUP (?) 17 | PASSINPUT DB 1 DUP (?) 18 | DATA ENDS 19 | 20 | ;***************** 21 | 22 | CODE SEGMENT 23 | 24 | START:MOV AX,DATA 25 | MOV DS,AX 26 | 27 | 28 | DEFINE_SCAN_NUM 29 | DEFINE_PRINT_STRING 30 | DEFINE_PRINT_NUM 31 | DEFINE_PRINT_NUM_UNS 32 | 33 | 34 | AGAIN:LEA SI,DATA1 35 | CALL PRINT_STRING 36 | LEA SI,DATA2 37 | CALL PRINT_STRING 38 | MOV SI,-1 39 | 40 | CALL SCAN_NUM 41 | MOV IDINPUT,CX 42 | MOV AX,CX 43 | MOV CX,0 44 | L1: INC CX 45 | CMP CX,TOTAL 46 | JE ERROR 47 | INC SI 48 | MOV DX,SI 49 | CMP IDS1[SI],AX 50 | JE PASS1 51 | CMP IDS2[SI],AX 52 | JE PASS2 53 | JMP L1 54 | 55 | 56 | PASS1:LEA SI,DATA3 57 | CALL PRINT_STRING 58 | CALL SCAN_NUM 59 | MOV PASSINPUT,CL 60 | MOV AX,DX 61 | MOV DX,0002H 62 | DIV DL 63 | MOV SI,AX 64 | MOV AL,CL 65 | MOV AH,00H 66 | CMP PASSWORDS1[SI],AL 67 | JNE ERROR 68 | JMP DONE 69 | 70 | PASS2:LEA SI,DATA3 71 | CALL PRINT_STRING 72 | CALL SCAN_NUM 73 | MOV PASSINPUT,CL 74 | MOV AX,DX 75 | MOV DX,0002H 76 | DIV DL 77 | MOV SI,AX 78 | MOV AL,CL 79 | MOV AH,00H 80 | CMP PASSWORDS2[SI],AL 81 | JNE ERROR 82 | JMP DONE 83 | 84 | 85 | 86 | ERROR:LEA SI,DATA4 87 | CALL PRINT_STRING 88 | PRINT 0AH 89 | PRINT 0DH 90 | MOV SI,0 91 | JMP AGAIN 92 | 93 | 94 | DONE: LEA SI,DATA5 95 | CALL PRINT_STRING 96 | PRINT 0AH 97 | PRINT 0DH 98 | LEA SI,DATA6 99 | CALL PRINT_STRING 100 | MOV SI,0 101 | 102 | CODE ENDS 103 | 104 | END START 105 | 106 | 107 | ret 108 | 109 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /Project #8 - ATM Machine/README.md: -------------------------------------------------------------------------------- 1 | # ATM Machine 2 | ## Table of Content 3 | - [ATM Machine](#atm-machine) 4 | * [Abstract](#abstract) 5 | * [Author](#author) 6 | 7 | ## Abstract 8 | In ATM machine, an electronic lock circuit is used to authorize the card. This circuit has two 9 | input codes: The card number that consists of 16 bits and the password that consists of 4 bits. 10 | If the bank has 20 customers only uses the cards. 11 | 12 | Construct their database and store it in the memory. Then write a program for card authorization. 13 | The inputs of the program are the card number and the password. 14 | 15 | The output is one bit (0/1) that means (denied/allowed). 16 | 17 | ## Author 18 | [Ahmed Hany](https://github.com/ahmedhany2001) 19 | -------------------------------------------------------------------------------- /Project #9 - Mononumeric substitution encryption/Project #9 - Mononumeric substitution encryption.asm: -------------------------------------------------------------------------------- 1 | include 'emu8086.inc' 2 | org 100h 3 | jmp start 4 | Buffer db 81 dup(00h) ; e7gezly 81 makan w gowahom 00H 5 | Buffer2 db 81 dup(00h) ; dup = 7a7ot fl amaken el ma7gooza di eh 6 | bzbt? 7 | msg1 db 0ah,0dh, 'Please choose the method you want , 1-encrypt 2- 8 | decrypt: $',0ah,0dh 9 | msg2 db 0ah,0dh, 'Enter your text: $' 10 | msg3 db 0ah,0dh, 'Your text after encryption is: $' 11 | msg4 db 0ah,0dh, 'Your text after decryption is: $' 12 | msg5 db 0ah,0dh, 'Enter your number: $' 13 | table1 db 97 dup (' 14 | '),1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25 15 | ,26 ; db = define byte 16 | table2 db ' ','abcdefghijklmnopqrstuvwxyz' 17 | start: 18 | ; Print ( bytala3 output 3la el screen ) awl message el heya 1- 19 | encrypt , 2- decrypt 20 | mov DX,offset msg1 21 | mov AH,09h ; to output any string on screen must move 09h into 22 | AH register , zy print fl c 23 | int 21h ; interrupt for output & input string 24 | ; take input from user 25 | mov AH,01h ; by2ra one character from the user zy scan fl c , 26 | momken tkon 1 or 2 ( encrypt or decrypt ) 27 | int 21h 28 | CMP AL,'1' ; el input taken mn el user is automatically 29 | inserted in AL 30 | JZ encrypt 31 | CMP AL,'2' 32 | JZ decrypt 33 | encrypt: 34 | ; Print tany message ( Enter yout text to be encrypted ) 35 | mov DX,offset msg2 36 | mov AH,09h ; b print out el m7toot fl DX 37 | int 21h 38 | 39 | mov BX,offset Buffer ; Takes the address of the buffer & 40 | moves it to BX register 41 | mov byte [BX],81 ; the string is max 80 chars long + enter , so 42 | we put them in the first byte of the buffer 43 | 44 | mov DX,BX 45 | mov AH,0Ah ; scanf for the buffer , take input string & store 46 | it in buffer 47 | int 21h 48 | 49 | mov AL,[BX+1] ; move the length of the string into AL , 50 | [BX+1] 3shan ana 7agazt f awl makan el size bta3 el buffer 51 | add AL,02 ; 02 3shan el buffer msh bybtedy mn awl makan 52 | 53 | mov AH,00h ; can not put an 8-bit register into a 16 bit 54 | register, so we must clear out AH first 55 | mov SI,AX ; Then we need another index register to hold 56 | this value which is the size of the string 57 | mov byte [BX+SI],'$' ; Now we can put the '$' at this position 58 | ( last position ), obtained by buffer address+size of string 59 | ; Encrypt 60 | lea BX, table1 ; table 1 feeha el numbers w 7at el address 61 | bta3 el table f BX 62 | lea SI, Buffer+2 ; 7at el address bta3 awl character fl SI 63 | call encryption ; 7aro7 l encryption 64 | 65 | ; Print el message el talta ( text after encryption ) 66 | mov DX, offset msg3 67 | mov AH, 09h 68 | int 21h 69 | ; Show result: 70 | mov SI, 2 71 | mov CL, [Buffer+1] 72 | mov CH,0 73 | lea BX, Buffer 74 | again: 75 | mov AL, [BX+SI] 76 | mov AH,0 77 | CALL PRINT_NUM_UNS 78 | inc SI 79 | loop again 80 | jmp start 81 | 82 | decrypt: 83 | mov DX,offset msg5 84 | mov AH,09h 85 | int 21h 86 | mov BX,offset Buffer 87 | mov byte [BX],81 88 | 89 | ;Take string from user and store it in buffer 90 | mov DX,BX 91 | mov AH,0Ah 92 | int 21h 93 | 94 | mov AL,[BX+1] 95 | add AL,02 96 | 97 | mov AH,00h 98 | mov SI,AX 99 | mov byte [BX+SI],'$' 100 | mov CL,[BX+1] 101 | mov CH,0 102 | mov SI,2 103 | lea DX,Buffer2 104 | mov DI,2 105 | ; betkhaly el decimal numbers el f table 1 hex w store it in buffer2 106 | redo: 107 | CLC 108 | mov AL,[BX+SI] 109 | sub AL,30h 110 | mov AH,10 111 | mul AH 112 | inc SI 113 | mov AH,[BX+SI] 114 | sub AH,30h 115 | add AH,AL 116 | XCHG BX,DX 117 | mov [BX+DI],ah 118 | XCHG BX,DX 119 | inc SI 120 | inc DI 121 | cmp [BX+SI], '$' 122 | jnz redo 123 | 124 | XCHG BX,DX 125 | mov byte [BX+DI],'$' 126 | ; decrypt 127 | lea BX, table2 128 | lea SI, Buffer2+2 129 | call decryption 130 | ; print el kelma after decryption 131 | mov DX, offset msg4 132 | mov AH, 09H 133 | int 21h 134 | ; show result: 135 | mov DX,offset Buffer2+2 136 | mov AH,09H ; (output string) 137 | int 21h 138 | jmp start 139 | ; wait for any key... 140 | exit: 141 | mov AH, 0 142 | int 16h 143 | 144 | ret 145 | encryption proc near 146 | next_char: 147 | cmp [SI], '$' ; end of string? 148 | je end_of_string 149 | mov AL, [SI] 150 | cmp AL, 'a' 151 | jb skip 152 | cmp AL, 'z' 153 | ja skip 154 | xlatb ; encrypt using table2 by xlat algorithm: al = 155 | ds:[bx + unsigned al] 156 | mov [SI], AL ; now el al feeha el 7arf f 7roo7 ry7a buffer 157 | w shyla el 7arf dah w 7ta makano el number corresponding to it 158 | skip: 159 | inc SI 160 | jmp next_char 161 | end_of_string: 162 | ret 163 | encryption endp 164 | ; this procedure prints out an unsigned 165 | ; number in AX (not just a single digit) 166 | ; allowed values are from 0 to 65535 (FFFF) 167 | PRINT_NUM_UNS PROC NEAR 168 | PUSH AX 169 | PUSH BX 170 | PUSH CX 171 | PUSH DX 172 | ; flag to prevent printing zeros before number: 173 | MOV CX, 1 174 | ; (result of "/ 10000" is always less or equal to 9). 175 | MOV BX, 10000 ; 2710h - divider. 176 | CMP AX, 0 177 | JZ print_zero 178 | 179 | CMP AX,20h 180 | JZ print_space 181 | 182 | CMP AX,10 183 | JB print_zero 184 | jmp begin_print 185 | 186 | print_zero: 187 | PUTC '0' 188 | 189 | jmp begin_print 190 | 191 | print_space: 192 | PUTC ' ' 193 | Jmp end_print 194 | 195 | begin_print: 196 | 197 | ; check divider (if zero go to end_print): 198 | CMP BX,0 199 | JZ end_print 200 | ; avoid printing zeros before number: 201 | CMP CX, 0 202 | JE calc 203 | ; if AX= 500ºC, a red led will turn on. 110 | 111 | Write a program that reads the temperature every 3 minutes and shows the LED condition. 112 | ### Project #8: ATM Machine 113 | In ATM machine, an electronic lock circuit is used to authorize the card. This circuit has two 114 | input codes: The card number that consists of 16 bits and the password that consists of 4 bits. 115 | If the bank has 20 customers only uses the cards. 116 | 117 | Construct their database and store it in the memory. Then write a program for card authorization. 118 | The inputs of the program are the card number and the password. 119 | 120 | The output is one bit (0/1) that means (denied/allowed). 121 | ### Project #9: Mononumeric substitution encryption: 122 | In the monoalphabetic substitution encryption, each alphabetic letter is substituted by another 123 | letter according to the following table: 124 | 125 | Plain text 126 | 127 | a b c d e f g h i j k l m 128 | Cipher text 129 | 130 | 1 2 3 4 5 6 7 8 9 10 11 12 13 131 | 132 | Plain text 133 | 134 | n O p q r s t u v w x y z 135 | 136 | Cipher text 137 | 138 | 14 15 16 17 18 19 20 21 22 23 24 25 26 139 | 140 | Construct this table and store it in the memory. 141 | 142 | Write a program that allowed you to enter a text message, encrypt this message using the 143 | stored table, then decrypt the cipher text to obtain the original text message. 144 | 145 | Omit any space between words in your message. 146 | 147 | ## Remarks 148 | 1. These assembly programs were run and tested on the x86 emulator [emu8086](https://emu8086.en.lo4d.com/windows#:~:text=Tutorial....-,Emu8086%20is%20a%20Microprocessor%20Emulator%20with%20an%20integrated%208086%20Assembler,memory%20and%20input%2Foutput%20devices.). 149 | 2. You can find a README file for every project describing it in further detail 150 | 3. Make sure to checkout the amazing contributors down in the contributors section :) 151 | 152 | 153 | ## Contribute with your code! 154 | ***Please make sure to do the following upon submitting a PR:*** 155 | - Follow the same file naming format. **ie:** _Project #(Number) - (Project Name)_ 156 | - Add a README with at least an explanation of the implemented concept. ( _the more info you add the more helpful it is :)_ ) 157 | - If the project already exists in the repo specify that this is another implementation in the file name. **ie:** _Project #(number) [Another Implementation]_ - (Project Name) 158 | - Most importantly, make sure to have tested the code thoroughly before submitting the PR. 159 | 160 | ## Contributors 161 | * [Yousef Kotp](https://github.com/yousefkotp) (Project 0,2,5) 162 | 163 | * [Adham Mohamed](https://github.com/adhammohamed1) (Project 4) 164 | 165 | * [Mohammed Battawy](https://github.com/MohamedBattawy) (Project 6) 166 | 167 | * [Ahmed Hany](https://github.com/ahmedhany2001) (Project 8) 168 | 169 | * [Abdelrahman ElAttar](https://github.com/abdelrahmanelattarr/) (Project 1) 170 | 171 | * [Ahmad Hazem](https://github.com/AhmadHazem) (Project 3) 172 | 173 | * Farah Nawar (Project 9) 174 | 175 | * Yousef Walid (Project 7) 176 | 177 | 178 | --------------------------------------------------------------------------------