segment codigo assume text ..start: mov ax,datos mov es,ax mov ds,ax mov ah,09 mov dx, msj int 21h ;leer buffer m ximo 5 digitos con signo mov dx,buffer mov ah,0ah int 21h cmp byte [buffer+2], '-' jne no_convierte mov byte [bandera],1 ;activa bandera de conversión jmp si_convierte no_convierte: mov ah,09 mov dx,no_ int 21h jmp transformar si_convierte mov ah,09 mov dx,si_ int 21h transformar: call aplana ;transformar a hexa xor ax,ax xor bx,bx mov cl,[buffer+1] mov si,buffer+1 add si,cx ; indice de recorrido sobre cadena std ; vamos de atras para adelante leemos la unidad lodsb ; carga la unidad add bx,ax ; suma la unidad a bx que acumulara la conversion a hex cmp cx,1 je salta dec cx ;cmp byte [bandera],1 ;jne convierte_hexa ; dec cx ;resta un digito mas por el signo convierte_hexa: xor ax,ax mov dx,[producto] ;primer factor de multiplicacion lodsb mul dx mov dx,[factor] add bx,ax mov ax,[producto] mul dx mov [producto],ax salta: loop convierte_hexa ;copia el valor convertido a hexa mov [c1], bx mov [c2], bx jmp next_ cmp byte [bandera],1 je next_ not word [c1] not word [c2] add word [c2],1b next_: cmp byte [next], 0 je fin ;representacion de 16 bits mov cx, 16 print: mov ah, 2 ; funcion de imprime caracter mov dl, '0' test bx, 1000000000000000b ; probar el primer bit mediante el AND del test sin guardar el resultado en bx jz cero ; mov [producto],bx ; and word [producto], 1000000000000000b ; cmp word [producto],0 ; jz cero mov dl, '1' cero: int 21h shl bx, 1 loop print mov dl, 'B' int 21h mov dx,nl mov ah,09 int 21h dec byte [next] cmp byte [next],2 jne c1_ mov dx, dos mov ah,09 int 21h mov bx, [c2] c1_: cmp byte [next],1 jne nada_ mov dx,uno mov ah,09 int 21h mov bx, [c1] nada_: jmp next_ fin: mov ah,4ch int 21h aplana: xor cx,cx mov cl,[buffer+1] mov si,buffer+2 add si,cx ; indice de recorrido sobre cadena dec si mov di,si ciclo: std lodsb sub al,30h stosb loop ciclo ret segment datos assume data msj db 'Ingresa un n£mero positivo o negativo entre [0 y 65535]:',10,13,'$' buffer db 7,0 resb 7 nb resb 4 ;mascara de 4 bits ob resb 8 hb resb 10 si_ db 13,10,'Si requiere conversion:',10,13,'$' no_ db 13,10,'No requiere conversion:',10,13,'$' factor dw 10 producto dw 10 bandera dw 0 ; cero no requiere conversion next db 3; c1 dw 0 c2 dw 0 nl db 13,10,'$' dos db 'complemento dos: ',13,10,'$' uno db 'complemento uno: ',13,10,'$' segment pila assume stack resb 100h