Untitled
unknown
plain_text
2 years ago
2.3 kB
4
Indexable
DEDOMENA SEGMENT
debug dw 0
digit db 3 dup(0)
DEDOMENA ENDS
KWDIKAS SEGMENT
ARXH:
MOV AX, DEDOMENA
MOV DS, AX
; Prompt the user to enter a decimal number
MOV DX, OFFSET digit
MOV AH, 09h
INT 21H
; Convert the entered decimal number to binary and print
CALL input_and_print_binary
; Exit the program
MOV AH, 4Ch
INT 21H
input_and_print_binary PROC
; Convert the entered decimal number to binary and print
CALL get_one_decimal_digit
MOV digit[2], AL ; Store the first digit
CALL get_one_decimal_digit
MOV digit[1], AL ; Store the second digit
CALL get_one_decimal_digit
MOV digit[0], AL ; Store the third digit
; Print the entered decimal number
CALL output_value_to_display
; Print the binary representation of the number
MOV CX, 3
MOV SI, 0
PRINT_BINARY_LOOP:
CALL output_binary_digit
INC SI
LOOP PRINT_BINARY_LOOP
RET
input_and_print_binary ENDP
output_value_to_display PROC
PUSH SI
PUSH AX
PUSH CX
PUSH BX
MOV CX, 0
MOV SI, 0
MOV AL, digit[SI]
MOV BL, 100
MUL BL
ADD CL, AL
INC SI
MOV AL, digit[SI]
MOV BL, 10
MUL BL
ADD CL, AL
MOV AL, digit[SI]
ADD CL, AL
MOV AX, CX
; Assuming that 199 is the port for output
OUT 199, AX
POP BX
POP CX
POP AX
POP SI
RET
output_value_to_display ENDP
output_binary_digit PROC
MOV AL, digit[SI]
CALL binary_conversion
MOV AH, 02h
INT 21H
RET
output_binary_digit ENDP
binary_conversion PROC
MOV CX, 8 ; 8 bits
MOV BX, 0000_0001b ; Mask for checking each bit
binary_conversion_loop:
AND AL, BX
JZ zero_bit
MOV DL, '1'
MOV AH, 02h
INT 21H
JMP next_bit
zero_bit:
MOV DL, '0'
MOV AH, 02h
INT 21H
next_bit:
SHR BX, 1
LOOP binary_conversion_loop
RET
binary_conversion ENDP
get_one_decimal_digit PROC
PUSH AX
PUSH BP
MOV BP, SP
AGAININPUT:
MOV AH, 01h
INT 21H
CMP AL, '0'
JB AGAININPUT
CMP AL, '9'
JA AGAININPUT
MOV AH, 0
SUB AL, 30H
MOV [BP-2], AL
POP BP
POP AX
RET
get_one_decimal_digit ENDP
KWDIKAS ENDS
SOROS SEGMENT STACK
db 256 dup(0)
SOROS ENDS
END ARXH
Editor is loading...
Leave a Comment