# 4.2 Conversion bin to dec + logic operations bit-to-bit

May 12th, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. ;Write a program that acquires two variables of type byte opA and opB in binary format by keyboard ('0' and '1' sequence) and writes the result of logic operation bitwise into a variable of type byte ris.
2. ;Logic expression bit-to-bit is:
3. ;C = NOT(A AND (NOT(B))) OR (A XOR B).
4.
5. ;IMPLEMENTATION
6. ;Acquisition binary values:
7. ;-It's need conversion of ASCII character read by keyboard
8. ;-User types binary values (ex.:“00011100”) separated by ENTER
9. ;Logic operations on byte carried out with specific instructions
10.
11. DIM EQU 8     ;Dimension of every binary number... 8bit
12. .MODEL small
13. .STACK
14. .DATA
15. opa DB ?
16. opb DB ?
17. ris DB ?
18. .CODE
19. .STARTUP
20. MOV ah,1
21. XOR bx,bx
22. MOV CX,DIM
23. ;The first cycle concerns first variable opa
24. ciclo1: int 21h    ;In input I can insert only 0 or 1
25.         SUB AL,'0'
26.         DEC CX
27.         SHL AL,CL  ;SHL and OR instructions convert my binary number to decimal number. SHL does: AL*2^CL. In a cycle is, for example: 1*2^7+0*2^6+1*2^5+etc... that is the conversion from binary to decimal
28.         OR BL,AL   ;L'OR sums in BL the values in decimal that corresponds at the bit at 1
29.         CMP CX,0
30.         JNZ ciclo1
31. INT 21h
32. MOV opa,BL  ;puts the converted number (to decimal) in opa
33. xor BX,BX
34. MOV CX,DIM
35. ciclo2: int 21h       ;This 2° cycle concerns opb
36.         SUB AL,'0'
37.         DEC CX
38.         SHL AL,CL
39.         OR BL,AL
40.         CMP CX,0
41.         JNZ ciclo2
42.
43. MOV opb,BL   ;put the decimal result in opb
44. ;Below there are the required logic operations by the text
45. MOV al,opb
46. not al
47. and al,opa
48. not al
49. mov ah,opa
50. xor ah,opb
51. or al,ah
52. mov ris,al
53.
54. .exit
55. END
56.
57. ;Then, since the text is unclear,
58. ;the text asks to write in input into two
59. ;variables 2 binary numbers, and convert them to decimal
60. ;and then to apply that logic operations that asks
61. ;at the end; so that logic operations are done
62. ;on operands with decimal value, because then the assembler
63. ;considers however the binary numbers since the logic operations
64. ;work bit-to-bit