Professional Documents
Culture Documents
Communication Steam
IDN : 6450/19
MOV AX,
AND AX, 1 ; AND the number with 1
JZ even ; If the result is zero, the number is even
; Otherwise, the number is odd
odd:
; Code to execute if the number is odd
JMP end
even:
; Code to execute if the number is even
end:
4. Write assembly language program that exchanges data at two different memory locations.
.MODEL SMALL
.STACK 100H
.DATA
location1 DW 1234h
location2 DW 5678h
.CODE
MOV AX, [location1] ; load value from location1 into AX
MOV BX, [location2] ; load value from location2 into BX
XCHG AX, BX ; exchange values of AX and BX
MOV [location1], AX ; store value of AX into location1
MOV [location2], BX ; store value of BX into location2
END
.MODEL SMALL
.STACK 100H
.DATA
array DB 'S', 'd', 'Z', 'G', 'n', 'B', 'W', 'A', 'P', 'R'
capNum DB 0
notCapNum DB 0
.CODE
MOV CX, 10 ; loop 10 times
MOV SI, 0 ; initialize array index
READ_LOOP:
MOV AL, array[SI] ; read a character from array
CMP AL, 'A' ; check if character is between 'A' and 'Z'
JL ELSE ; jump to ELSE if character is less than 'A'
CMP AL, 'Z' ; check if character is between 'A' and 'Z'
JG ELSE ; jump to ELSE if character is greater than 'Z'
INC capNum ; increment capNum if character is between 'A' and 'Z'
JMP END_IF
ELSE:
INC notCapNum ; increment notCapNum if character is not between 'A' and 'Z'
END_IF:
INC SI ; increment array index
LOOP READ_LOOP ; repeat for 10 times
; messages
capMsg DB 'Number of capital letters: $'
notCapMsg DB 'Number of non-capital letters: $'
END
1. Write an assembly language program for searching smallest number in an array.
.model small
.stack 100h
.data
array db 5, 2, 8, 1, 3, 7, 9, 4, 6, 0
n equ 10
.code
main proc
mov ax, @data
mov ds, ax
.model small
.stack 100h
.data
n dw 5
sum dw ?
.code
main proc
mov ax, @data
mov ds, ax
; Initialize oddNum to 0
MOV BX, 0
; Initialize evenNum to 0
MOV AX, 0
WHILE_LOOP:
; Check if count < 20
CMP CX, 20
JGE END_WHILE