Write an program using on DOSBOX (saved as encrypted.ASM file) to encrypt digits
ID: 3681700 • Letter: W
Question
Write an program using on DOSBOX (saved as encrypted.ASM file) to encrypt digits as below: input digit: 0 1 2 3 4 5 6 7 8 9 encrypted digit: 4 6 9 5 0 3 1 8 7 2 Program should accept a string consisting of digit and non digit characters. The encrypted string should be displayed in which only the digits are affected. Then user should be queried whether or not to terminate program. If 'Y' or 'y' terminate else request another input string. When you encrypt an already encrypted string you get back the original string.
this is my code:
%include "io.mac"
.STACK 100H
.DATA
str_prompt Db "Please input a string: ",0
out_msg Db " in change is ",0
query_msg Db "quit ",0
.UPDATA
num resb 100
.CODE
.STARTUP
PutStr str_prompt ; request a string. input
GetStr num,100
PutStr out_msg
mov EBX, num
read:
mov AL,[EBX]
cmp AL,0
je done
cmp AL,"9"
je convert_9
;cmp AH,"8"
;je convert_8
;cmp AH,"7"
;je convert_7
;cmp AH,"6"
;je convert_6
;cmp AH,"5"
;je convert_5
;cmp AL,"4"
;je convert_4
;cmp AL,"3"
;je convert_3
;cmp AL,"2"
;je convert_2
;cmp AL,"1"
;je convert_1
cmp AL,"0"
je convert_0
jmp skip
convert_9:
add AL, "2"
convert_8:
add AL, "7"-"8"
convert_7:
add AL, "8"-"7"
convert_6:
add AL, "2"-"6"
convert_5:
add AL, "3"-"5"
convert_4:
add AL, "0"-"4"
convert_3:
add AL,"5"-"3"
convert_2:
add AL,"9"-"2"
convert_1:
add AL,"6"-"1"
convert_0:
add AL,"4"-"0"
skip:
PutCh AL
inc EBX
jmp read
done:
.EXIT
It shows incorrect output but I cannout figure out the problems, please fix and give me some advice,thank you
Explanation / Answer
file: encrypt.asm %include "asm_io.inc" segment .data LF equ 0Ah ENCRYPTION_KEY db '4','6','9','5','0','3','1','8','7','2' userenter db "Enter a string to encrypt: ", 0 userexit db "Terminate? (y/n) ", 0 segment .bss input resd 1 segment .text global asm_main asm_main: enter 0,0 pusha start_encrypt: mov EAX, userenter call print_string mov EBX, input read_loop: mov AL,0 call read_char mov [EBX], AL inc EBX cmp AL, LF jne read_loop dec EBX mov byte[EBX], 0 mov EBX, input process_char: mov AL,0 mov AL,[EBX] cmp AL,0 je done cmp AL,'0' jl print_encrypted_char cmp AL,'9' jg print_encrypted_char sub AL,'0' convert_num: mov DL,AL mov EAX,ENCRYPTION_KEY add AL,DL mov AL,[EAX] call print_char inc EBX jmp process_char print_encrypted_char: call print_char inc EBX jmp process_char done: call print_nl mov EAX, userexit call print_string mov EAX, 0 call read_char mov DL,AL call read_char cmp DL,'y' je fin cmp DL,'Y' je fin jmp start_encrypt fin: call print_nl popa mov eax, 0 leave ret
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.