I\'m currently making a NASM 8086 program that Encrypts and Decrypts a message,
ID: 3805956 • Letter: I
Question
I'm currently making a NASM 8086 program that Encrypts and Decrypts a message, and was wondering if I can get some help on fixing my code so that it would be a fully functional program without any error. This is what I have so far.
; read a string
; encrypt it, and decrypt it.
org 100h
section .data
;___________________________DATA
prompt1: db "What is your secret message? $"
prompt2: db "The encrypted message is: $"
prompt3: db "The message after decryption is: $"
testout: db "*************** $"
key db 0Fh ; encryption key*
CRLF db 13, 10, '$' ; carriage return line feed
NULL db 0 ; null character
section .bss ; bss section*
buffer resb 80 ; 80 reserve bytes*
section .text
;_____________________________SCREEN TEXT
mov ah, 9 ; Used to print text stored in prompt1
mov dx, prompt1 ;
int 21h ; end text output
;_______________________INSTRING (KEYBOARD INPUT)
instring:
mov cx, 0 ; CX counts characters starts at 0
cld ; process string left to right*
mov di, buffer ; move buffer into data index*
mov ah, 1 ; read character from standard input*
int 21h ; read character*
while1: cmp al, 13 ; is character carriage return*
je endwhile1 ; if carriage return exit loop*
inc cx ; increment cx*
stosb ; store character just read into buffer*
int 21h ; read next character*
jmp while1 ; loop until all characters read*
endwhile1: ; endwhile1 (end of loop)*
mov byte [di], NULL ; store ASCII null character (end of array)*
mov dx, buffer ; dx is the address arg to print*?
;__________________________PRINT TO SCREEN
lp:
cld ; process string left to right*
lodsb
mov dl, al
mov ah, 2
int 21h
loop lp
;___________________________CODER (encode data)
; mov si,0 ; string index register(si = string index)***
while1:
cmp byte [si+msg],'$' ; looks for "$" to end loop***
je endwhile1 ; "$" ends loop***
mov al,[si+msg] ; moving through msg one character at a time***
xor al,[key] ; XOR value stored in al (encode)***
mov [si+coded],al ; move encoded character to al***
inc si ; increment si (array index counter)***
jmp while1 ;
endwhile1:
mov byte [si+coded],'$'
mov ah,9 ; write string to standard output ***
mov dx,coded ; store coded in output register ***
int 21h ; output coded ***
mov si,0
while2:
cmp byte [si+coded],'$'
je endwhile2
mov al,[si+coded]
xor al,[key]
mov [si+decoded],al
inc si
jmp while2
endwhile2:
mov byte [si+decoded],'$'
mov ah,2 ; write characer to standard output***
mov dl,13 ; store carrage carriage return code***
int 21h ; output carriage return***
mov dl,10 ; line feed code***
int 21h ; output line feed***
mov ah,9 ; write string to standard output ***
mov dx,decoded ; store decoded in output register ***
int 21h ; output decoded ***
exit:
mov ah, 04Ch ; DOS function: Exit program
mov al, 0 ; Returns exit code value
int 21h ; Call DOS (Terminate Program)
CODER:
cmp al, NULL ;if the character is null, we're done
je CODER
xor buffer, 0Fh
lodsb ;read next character
jmp CODER ;loop until done
Explanation / Answer
mov cl, 29
01
02
03
mov cl, 29
01
02
03
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.