Question
This is a code that must be tested through notepad and it must determine whether or not its condition is based on the use of
This is a code that must be tested through notepad and it must determine whether or not its condition is based on the use of strings:
.MODEL SMALL
.STACK
.DATA
NEWLINE db 0Dh, 0Ah, '$'
PROMPT db "Entre una cadena de caracteres: ",'$'
CHARACTER db ?
STRING db 81 dup('$')
MAX_LEN equ 80
CARRIAGE_RETURN equ 0Dh
LINE_FEED equ 0Ah
IS_VALID db ?
UNSIGNED_INT dw ?
TRUE equ 1h
FALSE equ 0h
.CODE
MAIN PROC
mov ax, @DATA
mov ds, ax
call NEW_LINE
call SHOW_PROMPT
call ASK_STRING
call NEW_LINE
call NEW_LINE
call SHOW_STRING
call IS_UNSIGNED_INT
cmp byte ptr IS_VALID, FALSE
jz GO_NEXT
call STRING_TO_UNSIGNED_INT
add word ptr UNSIGNED_INT, 10
call UNSIGNED_INT_TO_STRING
GO_NEXT:
call SHOW_STRING
call NEW_LINE
call NEW_LINE
mov ax, 4c00h ; exit program
int 21h ; return AL
RET
MAIN ENDP
;***********************************************************************************
UNSIGNED_INT_TO_STRING PROC
mov ax, UNSIGNED_INT
mov bx, 10
mov di, 0h
ANOTHER:
mov dx, 0h
div bx
add dl, '0'
mov STRING[di], dl
inc di
cmp ax, 0h
jnz ANOTHER
mov STRING[di], '$'
dec di
mov si, 0
OTHER:
mov ch, STRING[di]
mov cl, STRING[si]
mov STRING[di], cl
mov STRING[si], ch
dec di
inc si
cmp si, di
jb OTHER
RET
UNSIGNED_INT_TO_STRING ENDP
;***********************************************************************************
STRING_TO_UNSIGNED_INT PROC
mov ax, 0h
mov cx, 0h
mov bx, 10
mov di, 0h
mov cl, STRING[di]
BACK:
cmp cl, '$'
jz CONVERTED
mul bx
sub cl, '0'
add ax, cx
inc di
mov cl, STRING[di]
jmp BACK
CONVERTED:
mov UNSIGNED_INT, ax
RET
STRING_TO_UNSIGNED_INT ENDP
;***********************************************************************************
IS_UNSIGNED_INT PROC
mov byte ptr IS_VALID, TRUE
mov di, 0h
mov ah, STRING[di]
NEXT_CHAR:
cmp ah, '$'
jz DECIDIR
cmp ah, '0'
jb DECIDIR
cmp ah, '9'
ja DECIDIR
inc di
mov ah, STRING[di]
jmp NEXT_CHAR
DECIDIR:
jnz NOT_VALID
cmp di, 0h
jnz KEEP
NOT_VALID:
mov byte ptr IS_VALID, FALSE
KEEP:
RET
IS_UNSIGNED_INT ENDP
;***********************************************************************************
SHOW_PROMPT PROC
mov dx, offset PROMPT ; write all characters
mov ah, 09h ; in the standard output
int 21h ; DX has the offset of the first character
RET ; the last character must be '$'
SHOW_PROMPT ENDP
;***********************************************************************************
SHOW_CHARACTER PROC
mov ah, 02h ; write a character to standard ouput
mov dl, CHARACTER ; DL has the character
int 21H
RET
SHOW_CHARACTER ENDP
;***********************************************************************************
ASK_CHARACTER PROC
mov ah, 08h ; read a character without echo from standard input
int 21h ; AL stores the character read
mov CHARACTER, al
RET
ASK_CHARACTER ENDP
;************************************************************************
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started