קוד:
//The number
MOV BH, #0 //Set to something if its 2 bytes (DWORD)
MOV BL, #10010001b
CALL FUNC
FUNC: CMP BH, #0
JNE BBB
MOV AL, BL
CALL FUNCIT
MOV BL, AL
RET
BBB: MOV AL, BH
CALL FUNCIT
MOV BH, AL
MOV AL, BL
CALL FUNCIT
MOV BL, AL
RET
FUNCIT: MOV AH, #0 //stores the result
MOV CH, #4 //Loop counter
MOV CL, #00000001b //Bit Pointer
AGAIN1: AND AL, CL //Check the bit CL points to
JZ ISOFF 1
ISON1: ROL CL, 1
OR AH, CL
JMP NEXT1
ISOFF1: ROL CL, 1
NEXT1: ROL CL, 1
DEC CH
JNZ AGAINN1
MOV CH, #4 //Loop counter
MOV CL, #00000010b //Bit Pointer
AGAIN2: AND AL, CL //Check the bit CL points to
JZ ISOFF 2
ISON2: ROR CL, 1
OR AH, CL
JMP NEXT1
ISOFF2: ROR CL, 1
NEXT2: ROL CL, 3
DEC CH
JNZ AGAINN2
MOV AL, AH //Returns the reuslt(AH) in AL
RET