Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;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.
- ;Logic expression bit-to-bit is:
- ;C = NOT(A AND (NOT(B))) OR (A XOR B).
- ;IMPLEMENTATION
- ;Acquisition binary values:
- ;-It's need conversion of ASCII character read by keyboard
- ;-User types binary values (ex.:“00011100”) separated by ENTER
- ;Logic operations on byte carried out with specific instructions
- DIM EQU 8 ;Dimension of every binary number... 8bit
- .MODEL small
- .STACK
- .DATA
- opa DB ?
- opb DB ?
- ris DB ?
- .CODE
- .STARTUP
- MOV ah,1
- XOR bx,bx
- MOV CX,DIM
- ;The first cycle concerns first variable opa
- ciclo1: int 21h ;In input I can insert only 0 or 1
- SUB AL,'0'
- DEC CX
- 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
- OR BL,AL ;L'OR sums in BL the values in decimal that corresponds at the bit at 1
- CMP CX,0
- JNZ ciclo1
- INT 21h
- MOV opa,BL ;puts the converted number (to decimal) in opa
- xor BX,BX
- MOV CX,DIM
- ciclo2: int 21h ;This 2° cycle concerns opb
- SUB AL,'0'
- DEC CX
- SHL AL,CL
- OR BL,AL
- CMP CX,0
- JNZ ciclo2
- MOV opb,BL ;put the decimal result in opb
- ;Below there are the required logic operations by the text
- MOV al,opb
- not al
- and al,opa
- not al
- mov ah,opa
- xor ah,opb
- or al,ah
- mov ris,al
- .exit
- END
- ;Then, since the text is unclear,
- ;the text asks to write in input into two
- ;variables 2 binary numbers, and convert them to decimal
- ;and then to apply that logic operations that asks
- ;at the end; so that logic operations are done
- ;on operands with decimal value, because then the assembler
- ;considers however the binary numbers since the logic operations
- ;work bit-to-bit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement