Untitled

 avatar
unknown
plain_text
2 years ago
1.5 kB
3
Indexable
ORG 100h

input_buffer db 255, 0 ; Reserve space for the input string
output_buffer db 510  ; Reserve space for the output octal digits

MOV AH, 0Ah       ; DOS function to read a string from the keyboard
MOV DX, offset input_buffer ; Load the address of the input buffer into DX
INT 21h           ; Read the string into the input buffer

MOV SI, offset input_buffer+1 ; Load the address of the input buffer into SI
MOV DI, offset output_buffer ; Load the address of the output buffer into DI

.loop:
    LODSB         ; Load the next character from the input buffer into AL
    MOV BL, AL
    MOV BH, 0
    MOV CX, 3
    xor AX, AX
    .loop2:
        SHL BL, 1
        RCL AH, 1
        RCL BH, 1
        LOOP .loop2
    OR AH, '0' ; Convert the first octal digit to ASCII character
    MOV [DI], AH ; Store the first octal digit in the output buffer
    INC DI
    MOV AH, BH ; Get the second octal digit
    OR AH, '0' ; Convert the second octal digit to ASCII character
    MOV [DI], AH ; Store the second octal digit in the output buffer
    INC DI
    CMP SI, offset input_buffer+1+[input_buffer] ; Check if the end of the input buffer has been reached
    JBE .done
    JMP .loop

.done:
    MOV [DI], '$' ; Null-terminate the output buffer
    MOV AH, 09h   ; DOS function to output a string
    MOV DX, offset output_buffer ; Load the address of the output buffer into DX
    INT 21h       ; Output the octal representation to the screen

MOV AH, 4Ch       ; DOS function to exit the program
INT 21h           ; Exit the program