0% found this document useful (0 votes)
25 views

Flow Control Instruction 2

This document contains code to print stars in a loop and to convert characters to hexadecimal values. It contains code to: 1) Print 15 stars in a nested loop to output a block of stars. 2) Prompt the user to enter a character, display the character's ASCII code in hexadecimal format with two digits, and loop to allow multiple conversions. 3) Convert the character to hexadecimal by shifting and masking bits, converting numeric values to characters, and handling values above 9 as hexadecimal letters A-F.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Flow Control Instruction 2

This document contains code to print stars in a loop and to convert characters to hexadecimal values. It contains code to: 1) Print 15 stars in a nested loop to output a block of stars. 2) Prompt the user to enter a character, display the character's ASCII code in hexadecimal format with two digits, and loop to allow multiple conversions. 3) Convert the character to hexadecimal by shifting and masking bits, converting numeric values to characters, and handling values above 9 as hexadecimal letters A-F.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

********************************************

***********print star***********
.model small
.stack 100h
.data

.code
main proc
mov ax,@data
mov ds,ax

mov cx,15
l1:
mov bx,cx

l2:
mov dl,'*'
mov ah,2
int 21h

loop l2

mov ah,2
mov dl,0ah
int 21h
mov dl,0dh
int 21h

mov cx,bx

loop l1
ret

exit:
mov ah,4ch
int 21h

main endp
***********************************************************
*************convert hexa************
.model small
.stack 100h
.data
nl equ 0ah,0dh
M1 DB nl,'TYPE A CHARACTER :','$'
M2 DB nl,'THE ASCII CODE OF '
C1 DB ?,' IN HEXA IS ','$'
.code
main proc
mov ax,@data
mov ds,ax

BEGIN:
MOV AH,9 ;prompt user
LEA DX,M1
INT 21h
MOV AH,1 ;read char.
INT 21H
CMP AL,0DH ;if CR exit
JE exit
MOV C1,AL ;store char.
MOV BL,AL ;take a copy of char

MOV AH,9 ;display 2nd MSG


LEA DX,M2
int 21h

MOV CL,4
SHR C1,CL ;prapare for display 1st half
;* note below
ADD C1,30H ;convert to char.
MOV DL,C1
JMP EXE1

continue: AND BL,0FH ;convert 2nd half to char.


CMP BL,9 ;if >9 mean A,B,C…..hex ch.
JG ERROR_

ADD BL,30H ;convert to char.


MOV DL,BL
JMP EXE2
EXE1: MOV AH,2 ;1st half displayed
INT 21H
JMP continue
EXE2: MOV AH,2
INT 21H ;2nd half displayed

JMP BEGIN ;ask if you want to do it again


;------------
ERROR_: ADD BL,37H ;convert to A,B,C…. hexa ch.
MOV DL,BL
MOV AH,2 ;display it

INT 21H
exit:
mov ah,4ch
int 21h

main endp

You might also like