I have written this code, but I only get the reversed string as output. I want the 1's complement of the reversed string too as output. I know how can I get this. When I edit my code and make it ready for 1's complement of reversed string, my reversed string is no more!
Test case:
input: 11010110
output(that is needed):
Reversed string: 01101011 1's Complement of it: 10010100
My code:
;REVERSING 8-BIT BINARY NO.
.MODEL
.STACK 100H
.DATA
STR DB 'Enter the binary number (max 8-bit) : $'
STR2 DB 0DH,0AH,'REVERSED STRING : $'
STR3 DB 'THE 1S COMPLEMENT OF IT: $'
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX
LEA DX, STR ; display STR
MOV AH, 9
INT 21H
XOR BL, BL ; CLEAR BL
MOV CX, 8 ; loop for 8 times
MOV AH, 1
INPUT:
INT 21H
CMP AL, 0DH ; compare digit with carriage return (ENTER)
JZ END ; jump to END, if carriage return (JUMP IF ZERO)
AND AL, 01H ; convert ascii to decimal code
SHL BL, 1 ; rotate BX to left by 1 bit
OR BL, AL ; set the LSB of BX with input
LOOP INPUT ; jump to INPUT
END:
MOV AL, BL ; copy BL into AL
MOV CX, 8 ; loop for 8 times
LP: ; loop
SHL AL, 1 ; shift AL to left by 1 bit
RCR BL, 1 ; rotate BL right through carry
LOOP LP ; jump to LP
LEA DX, STR2 ; load and display STR2
MOV AH, 9
INT 21H
MOV CX, 8
MOV AH, 2 ; output function
OUTPUT:
SHL BL, 1 ; shift left BL by 1 bit
JNC ZERO ; jump to label ZERO if CF=0
MOV DL, 31H ; set DL=1. DL=0 for 1's compelement.
JMP DISPLAY ; jump to DISPLAY
ZERO:
MOV DL, 30H ; set DL=0. DL=1 for 1's complement.
DISPLAY:
INT 21H ; display digit
LOOP OUTPUT ; output
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN