
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
try: | |
CR EQU 13 | |
LF EQU 10 | |
IMPRIMIR EQU 9 | |
FIN EQU 4C00H | |
DOS EQU 21H | |
TAB EQU 09H | |
DATOS SEGMENT | |
ASCII DB 'A','B','C','D','E','F','G','H' | |
ESPACIO DB CR,LF,"$" | |
BINARIO DB 64 DUP (?),"$" | |
MENSAJE1 DB CR,LF,TAB,"ANTES DE LA CONVERSION: ","$" | |
MENSAJE2 DB CR,LF,TAB,"DESPUES DE LA CONVERSION: ","$" | |
DATOS ENDS | |
PILA SEGMENT STACK 'STACK' | |
DW 128 DUP('P') | |
PILA ENDS | |
CODIGO SEGMENT | |
CONV PROC FAR | |
ASSUME CS:CODIGO,SS:PILA,DS:DATOS | |
MOV AX,DATOS | |
MOV DS,AX | |
LEA DX,MENSAJE1 | |
CALL ESCRIBE | |
LEA DX,ESPACIO | |
CALL ESCRIBE | |
LEA DX,ASCII | |
CALL ESCRIBE | |
LEA DX,ESPACIO | |
CALL ESCRIBE | |
LEA DX,BINARIO | |
CALL ESCRIBE | |
LEA DX,ESPACIO | |
CALL ESCRIBE | |
LEA SI,ASCII | |
LEA DI,BINARIO | |
CALL ASCII2BIN | |
LEA DX,MENSAJE2 | |
CALL ESCRIBE | |
LEA DX,ESPACIO | |
CALL ESCRIBE | |
LEA DX,ASCII | |
CALL ESCRIBE | |
LEA DX,ESPACIO | |
CALL ESCRIBE | |
LEA DX,BINARIO | |
CALL ESCRIBE | |
LEA DX,ESPACIO | |
CALL ESCRIBE | |
CALL SALIR | |
CONV ENDP | |
ASCII2BIN PROC NEAR | |
XOR AX,AX | |
MOV CX,8 | |
ASCII1: | |
MOV AL,[SI] | |
PUSH CX | |
MOV CX,8 | |
LOOP_SHIFT: | |
SHL AL,1 | |
JC BIN_UNO | |
MOV [DI],BYTE PTR '0' | |
JMP CICLO_SHIFT | |
BIN_UNO: | |
MOV [DI],BYTE PTR '1' | |
CICLO_SHIFT: | |
INC DI | |
LOOP LOOP_SHIFT | |
POP CX | |
INC SI | |
LOOP ASCII1 | |
RET | |
ASCII2BIN ENDP | |
ESCRIBE PROC | |
MOV AH,IMPRIMIR | |
INT DOS | |
RET | |
ESCRIBE ENDP | |
SALIR PROC NEAR | |
MOV AX,FIN | |
INT DOS | |
SALIR ENDP | |
CODIGO ENDS | |
END CONV |