TASM Program to display the contents of 16 bit flag register
On-campus and online computer science courses to Learn the basic concepts of Computer Science.This tutorial will cover c ,c++, java, data structure and algorithm,computer graphics,microprocessor,analysis of algorithms,Digital Logic Design and Analysis,computer architecture,computer networks,operating system.
Objective:
Write an
assembly language program to display the contents of 16 bit flag register.
Prerequisite:
TASM assembler
Description:
To
display the contents of flag register pushf and pop instruction. Each bit of
flag register is then masked off with 1 and all 0’s (i.e. 1000 0000 0000
0000(16 bit) à 8000h)
and based on the result of masking either 0 (30h) or 1 (31h) is get displayed
on the screen. Each bit of the above 16 bit number gets shifted in right
direction by 1 position before masking to obtain the next bit position of flag
register. This whole procedure gets repeated 16 times.
Algorithm
- Start
- Initialize data segment through AX register in
the DS register.
- Display the flag bit names as “X X X X O D I T SF
ZF x AF X PF X CF ”
- Push the contents of flag register to a stack
- Pop the contents of stack to register to any 16
bit register (say BX =0000 0100 1000 1001)
- Move the contents of BX to temporary variable say t
- Move the 8000h number to AX.(AXß 8000h)
- Move the count as 16(in decimal) to CX register
(as 16 bit flag register)
- Move the contents of temporary variable t to
BX.
- And the contents of BX and AX.
- If zero flag is set then goto the step no
14 otherwise goto step no. 12
- Move the 31h to DL register.
- Make the unconditional jump to a step no. 15
- Move the
30h to DL register.
- Preserve
the (8000h ) number from AX in t1 temporary variable. (As while displaying
30h or 31 h AH register get modified as 02h function is moved of INT 21h).
- Display the contents of DL register.
- Move the contents of t1 to AX register back (As
while displaying 30h or 31 h AH register get modified as 02h function is
moved of INT 21h).
- Rotate the contents of AX by 1 positions in
right direction.
- Repeat step no 5 to 17 till count CX reaches to
0.
- Stop.
Data Segment msg db 0dh,0ah,"-- -- -- -- OF DF IF TF SF ZF -- AF -- PF -- CF $" newl db 0dh,0ah,"$" flag dw ? Data ends Code Segment assume CS:Code,DS:Data start: mov ax,Data mov DS,ax mov dx,offset msg mov ah,09h int 21h mov dx,offset newl mov ah,09h int 21h cli stc std pushf pop bx mov flag,bx mov cx,16 mov bx,8000h loops: mov ax,flag and ax,bx jz zero mov dl,31h mov ah,02h int 21h jmp space zero: mov dl,30h mov ah,02h int 21h space: mov dl,' ' mov ah,02h int 21h mov ah,02h int 21h ror bx,1 loop loops mov ah,4ch int 21h Code ends end startoutput:-
OUTPUT before using CLI,STC,STD: C:\TASM\BIN>tasm flags.asm Turbo Assembler Version 4.1 Copyright (c) 1988, 1996 Borland International Assembling file: flags.asm Error messages: None Warning messages: None Passes: 1 Remaining memory: 453k C:\TASM\BIN>tlink flags.obj Turbo Link Version 7.1.30.1. Copyright (c) 1987, 1996 Borland International Warning: No stack C:\TASM\BIN>flags -- -- -- -- OF DF IF TF SF ZF -- AF -- PF -- CF 0 0 1 1 0 0 1 0 0 0 0 0 0 0 1 0 OUTPUT after using CLI,STC,STD: C:\TASM\BIN>tasm flags.asm Turbo Assembler Version 4.1 Copyright (c) 1988, 1996 Borland International Assembling file: flags.asm Error messages: None Warning messages: None Passes: 1 Remaining memory: 453k C:\TASM\BIN>tlink flags.obj Turbo Link Version 7.1.30.1. Copyright (c) 1987, 1996 Borland International Warning: No stack C:\TASM\BIN>flags -- -- -- -- OF DF IF TF SF ZF -- AF -- PF -- CF 0 0 1 1 0 1 0 0 0 0 0 0 0 0 1 1 --------------------------------
0 comments: