-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathbitwise_not_ones_complement_demonstration.asm
More file actions
90 lines (78 loc) · 3.54 KB
/
bitwise_not_ones_complement_demonstration.asm
File metadata and controls
90 lines (78 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
; =============================================================================
; TITLE: Bitwise Logical NOT Operation (One's Complement)
; DESCRIPTION: This program demonstrates the 8086 'NOT' instruction, which
; performs a bitwise logical negation. This operation inverts
; every bit in the operand (0 becomes 1, and 1 becomes 0), effectively
; calculating the One's Complement of a value.
; AUTHOR: Amey Thakur (https://github.com/Amey-Thakur)
; REPOSITORY: https://github.com/Amey-Thakur/8086-ASSEMBLY-LANGUAGE-PROGRAMS
; LICENSE: MIT License
; =============================================================================
.MODEL SMALL
.STACK 100H
; -----------------------------------------------------------------------------
; DATA SEGMENT
; -----------------------------------------------------------------------------
.DATA
; Original value: 0000 1111 (0FH / 15 decimal)
ORIG_VAL DB 0FH
; Buffer for negation result
NOT_RES DB ?
; -----------------------------------------------------------------------------
; CODE SEGMENT
; -----------------------------------------------------------------------------
.CODE
MAIN PROC
; --- Step 1: Initialize Data Segment ---
MOV AX, @DATA
MOV DS, AX
; --- Step 2: Load Target Value ---
MOV AL, ORIG_VAL ; AL = 0000 1111
; --- Step 3: Execute Bitwise NOT ---
; Truth Table for NOT:
; Input 0 -> Output 1
; Input 1 -> Output 0
NOT AL ; Invert all bits in AL
; Calculation Trace:
; Input: 0 0 0 0 1 1 1 1 (0FH)
; Output: 1 1 1 1 0 0 0 0 (F0H)
; --- Step 4: Persist Results ---
MOV NOT_RES, AL
; --- Step 5: Termination ---
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
; =============================================================================
; TECHNICAL NOTES & ARCHITECTURAL INSIGHTS
; =============================================================================
; 1. ONE'S COMPLEMENT LOGIC:
; The NOT instruction is a unary operation (takes one operand). It is the
; fundamental building block for calculating One's Complement. To derive
; the Two's Complement (used for signed arithmetic), one would follow
; NOT with an 'INC' (Increment) instruction.
;
; 2. FLAG BEHAVIOR (CRITICAL):
; Unlike most arithmetic and logic instructions (AND, OR, XOR, ADD), the
; NOT instruction does NOT affect any status flags in the 8086.
; - The Zero Flag (ZF), Sign Flag (SF), and Carry Flag (CF) remain exactly
; as they were before the NOT execution.
; - If a program needs to check the result for zero or sign, an explicit
; comparison (CMP) or a TEST instruction must follow.
;
; 3. NEG vs NOT:
; - NOT: Bitwise inversion (Logical negation).
; - NEG: Arithmetic negation (calculates Two's Complement: 0 - Value).
; NEG DOES affect flags, including setting the Carry Flag if the
; input is not zero.
;
; 4. BIT REVERSAL vs BIT INVERSION:
; Beginners often confuse inversion (NOT) with reversal (swapping bit
; positions). NOT merely flips the state of each independent bit without
; moving them.
;
; 5. ELECTRICAL PERSPECTIVE:
; At the hardware level, the NOT instruction corresponds to a series of
; parallel CMOS Inverters. It is one of the most electrically simple and
; fastest instructions the CPU can execute.
; = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =