Additional Programming Examples
Additional Programming Examples
CODE ENDS
END START
DATA SEGMENT
arr db 02H,03H,12H,13H,14H ; byte array
max db ? ; Variable to store max element, initialized to zero as current max value
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START:
MOV AX, DATA ; initialize data segment
MOV DS, AX
CODE ENDS
END START
DATA SEGMENT
arr db 02H,03H,12H,13H,14H ; byte array
max db 20H ; Variable to store minimum element, initialized with a maximum value
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START:
MOV AX, DATA ; initialize data segment
MOV DS, AX
CODE ENDS
END START
DATA SEGMENT
NUM DB 10101010b ; 8-bit number for which parity needs to be calculated
; Suffix b indicates the number is binary
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
MOV AX, DATA ; Initialize DS register (Data Segment)
MOV DS, AX
; Calculate parity
MOV AL, NUM
PARITY_LOOP:
TEST AL, 1 ; Test the least significant bit
JNZ SET_PARITY ; If it's set, set the parity flag
SHR AL, 1 ; Right shift AL
JMP PARITY_CHECK ; Jump to the parity check
SET_PARITY:
INC AH ; Increment the parity flag
SHR AL, 1 ; Right shift AL
PARITY_CHECK:
TEST AL, AL ; Check if AL is zero
JNZ PARITY_LOOP ; If not zero, continue the loop
; AH now contains the parity flag (1 for odd parity, 0 for even parity)
CODE ENDS
END START