Showing posts with label system programming code. Show all posts
Showing posts with label system programming code. Show all posts

Saturday, February 7, 2015

stack implementation in C++

#include<iostream>
#include<cstdlib>
using namespace std;
class stack
{public:
int top[8],arr[8][125];
void push(int a,int b);
int pop(int a);
stack()
{top[0]=-1;
top[1]=-1;
top[2]=-1;
top[3]=-1;
top[4]=-1;
top[5]=-1;
top[6]=-1;
top[7]=-1;
}
};
void stack::push(int a,int b)
{arr[a][++top[a]]=b;
}
int stack::pop(int a)
{return arr[a][top[a]--];
}
int main()
{stack s;int i,j,k,n,p,q;
 for(i=0;i<4;i++)
 {cout<<"Enter the array no:";
  cin>>n;
  cout<<"Enter the element\n";
  for(k=0;k<125;k++)
  { cin>>p;
    s.push(n,p);
  }
 }
 for(i=0;i<8;i++)
 {cout<<"Enter the array:";
  cin>>n;
  for(j=0;j<125;j++)
   {k=s.pop(n);
    cout<<k<<endl;
   }
 }
}

Tuesday, April 15, 2014

File operation in Assembly language 8086

;random access from file
.model small
.stack 64
.data
name1 label byte
maxlen db 5
actlen db ?
record db 5 dup(' '),'$'
nl db 13,10,'$'
filename db 'c:\rec.asm',00h
filehandle1 dw ?
recno dw ?    
error db 10,13,"error $"
msg db 10,13,"recno:- $"
.code
main proc near
mov ax,@data
mov ds,ax

mov ah,3ch
mov cx,00
lea dx,filename
int 21h

jc end1
mov filehandle1,ax
a10:
mov ah,0ah
lea dx,name1
int 21h
cmp actlen,0
jbe a20
mov ah,40h
mov bx,filehandle1
mov cx,5
lea dx,record
int 21h

mov ah,09h
lea dx,nl
int 21h

jmp a10

a20:
mov ah,3eh
mov bx,filehandle1
int 21h

mov ah,3dh
mov al,00
lea dx,filename
int 21h
jc end1

mov filehandle1,ax

mov ah,09h
lea dx,msg
int 21h

mov ah,01h
int 21h

sub al,31h
mov ah,00
mul maxlen
mov recno,ax

mov ah,42h
mov al,00
mov bx,filehandle1
mov cx,00
mov dx,recno
int 21h

mov ah,3fh
mov bx,filehandle1
mov cx,5
lea dx,record
int 21h

mov ah,09h
lea dx,record
int 21h
 
 
mov ah,3eh
mov bx,filehandle1
int 21h
jmp end2
 
 
end1:  
mov ah,09h
lea dx,error
int 21h
end2:
mov ax,4c00h
int 21h
main endp
end main

Monday, April 14, 2014

string copying in assembly language 8086

.model small
.stack 64
.data
str1 db 'pawan samarwal$'
str2 db 20 dup(' '),'$'

.code
main proc far
mov ax,@data
mov ds,ax
mov es,ax
cld
mov cx,20
lea di,str1
lea si,str2
rep movsb
mov ah,09h
lea dx,str1
int 21h
mov ah,4ch
int 21h
main endp
end main

String comparison in assembly language 8086

DATA SEGMENT
        STR1 DB "ENTER FIRST STRING HERE ->$"
        STR2 DB "ENTER SECOND STRING HERE ->$"
        STR11 DB "FIRST STRING : ->$"
        STR22 DB "SECOND STRING: ->$"

        INSTR1 DB 20 DUP("$")
        INSTR2 DB 20 DUP("$")
        NEWLINE DB 10,13,"$"
        N DB ?
        S DB ?
        MSG1 DB "BOTH STRING ARE SAME$"
        MSG2 DB "BOTH STRING ARE DIFFERENT$"

DATA ENDS

CODE SEGMENT

        ASSUME DS:DATA,CS:CODE
START:

        MOV AX,DATA
        MOV DS,AX

        LEA SI,INSTR1
        LEA DI,INSTR2

;GET STRING
        MOV AH,09H
        LEA DX,STR1
        INT 21H

        MOV AH,0AH
        MOV DX,SI
        INT 21H


        MOV AH,09H
        LEA DX,NEWLINE
        INT 21H

        MOV AH,09H
        LEA DX,STR2
        INT 21H

        MOV AH,0AH
        MOV DX,DI
        INT 21H


        MOV AH,09H
        LEA DX,NEWLINE
        INT 21H


;PRINT THE STRING

        MOV AH,09H
        LEA DX,STR11
        INT 21H

        MOV AH,09H
        LEA DX,INSTR1+2
        INT 21H

        MOV AH,09H
        LEA DX,NEWLINE
        INT 21H

        MOV AH,09H
        LEA DX,STR22
        INT 21H

        MOV AH,09H
        LEA DX,INSTR2+2
        INT 21H

        MOV AH,09H
        LEA DX,NEWLINE
        INT 21H

;STRING COMPARISION
        MOV BX,00

        MOV BL,INSTR1+1
        MOV BH,INSTR2+1

        CMP BL,BH
        JNE L1

        ADD SI,2
        ADD DI,2

      L2:MOV BL,BYTE PTR[SI]
        CMP BYTE PTR[DI],BL
        JNE L1
        INC SI
        INC DI
        CMP BYTE PTR[DI],"$"
        JNE L2

        MOV AH,09H
        LEA DX,MSG1
        INT 21H

        JMP L5

      L1:MOV AH,09H
        LEA DX,MSG2
        INT 21H



     L5:
        MOV AH,09H
        LEA DX,NEWLINE
        INT 21H

        MOV AH,4CH
        INT 21H


CODE ENDS
END START

TSR DIGITAL CLOCK in ASSEMBLY LANGUAGE 8086

I've been trying to write TSR (Terminate-Stay-Resident) programs (in general) in Assembly (16-bit) for MS-DOS. I've read through a Wikipedia page on TSR and also a page on using it specifically in DOS (but it seems to be teaching it in C and not Assembly directly). I've looked at a site with tons of DOS interrupt documentation and find this one, this one, and another most relevant to TSR programs. I can't post all of the links because as a new user I can have up to 2 hyperlinks on a post.
So, I've tried writing a (seemingly) very simple TSR program in real mode flat model (.COM file format) in NASM. Here's the code:

creating digital clock

.model small
.stack 64h
code segment
assume cs:code
begin :
jmp tsr
address dd ?
str db ':','$'
hrs db ?
min db ?
sec db ?
num db 10
h db 2 dup(0)
m db 2 dup(0)
s db 2 dup(0)

clrscrn proc near
mov ax,0600h
mov bh,34h
mov cx,0000h
mov dx,2060h
int 10h
ret
clrscrn endp
set proc near
mov ah,02h
mov bh,00h
mov dh,0ah
mov dl,0ah
int 10h
ret
set endp

getv proc near
mov ah,2ch
int 21h

mov al,ch
mov ah,00
div num
mov bl,ah
mov dl,al
add dl,30h
mov ah,02h
int 21h
mov dl,bl
add dl,30h
mov ah,02h
int 21h
mov ah,09h
lea dx,str
int 21h
mov ah,2ch
int 21h
mov al,cl
mov ah,00h
div num
mov bl,ah
mov dl,al
add dl,30h
mov ah,02h
int 21h
mov dl,bl
add dl,30h
mov ah,02h
int 21h
mov ah,09h
lea dx,str
int 21h
mov ah,2ch
int 21h
mov al,dh
mov ah,00h
div num
mov bl,ah
mov dl,al
add dl,30h
mov ah,02h
int 21h
mov dl,bl
add dl,30h
mov ah,02h
int 21h
ret
getv endp


clock proc near
mov cl,100
b11:
call clrscrn
call set
call getv
call clrscrn
loop b11
ret
clock endp

l1:
mov ax,cs
mov ds,ax
mov es,ax
mov ah,00h
mov al,03h
int 10h
in al,60h
cmp al,01
jne e1
call clock
e1:
jmp dword ptr cs:address

tsr:
mov ax,cs
mov ds,ax
mov es,ax
mov ah,35h
mov al,09h
int 21h
mov word ptr address,bx
mov word ptr address+2,es
mov ah,25h
mov al,09h
mov dx,offset l1
int 21h
mov ah,31h
mov dx,offset tsr
int 21h
code ends
end begin

key identification in assembly language 8086

.model small
.stack 64h
.data
st1 db 'home $'
st2 db 'other $'
CTR DB 00H
.code
MAIN PROC FAR
MOV AX,@DATA
MOV DS,AX
A20:
MOV AH,10H
INT 16H
CMP Ah,47h
JE B10
MOV AH,09H
LEA DX,ST2
INT 21H

CMP CTR,09H
JNE A50
jmp a20
 B10:
 MOV AH,09H
 LEA DX,ST1
 INT 21H
 JMP A20
a50:
 MOV AH,4CH
 INT 21H
 MAIN ENDP
 END MAIN

screensaver in SP using keyboard input 8086

pawan macro
mov ax,0600h
mov cx,0000h
mov dx,184fh
mov bh,a
int 10h
endm
.model small
.stack 64

.data
ctr db 10h
tik db 'pawan$'
a db 00h
.code
main proc far
mov ax,@data
mov ds,ax

a20:
inc ctr
mov cx,0fh
pawa:
inc a
loop pawa
mov ah,10h
int 16h
cmp al,0e0h
je a10
jmp a20
a10:
pawan
jmp a20

mov ah,4ch
int 21h
main endp
end main

Saturday, April 5, 2014

Moving CAR in ASSEMBLY LANGUAGE

int 10h is a video BIOS interrupt that is older than dirt and cannot be accessed from user mode in current operating systems

.model small
.stack 64
.data
tik dw ?
a db 05h
b db 05h
c db 08h
d db 0fh
e db 06h
f db 12h
str db '   0     0 ','$'
ctr db 00
.code
main proc far
mov ax,@data
mov ds,ax
pawan:
mov ah,00h
mov al,03h
int 10h
inc ctr
mov ah,02h
mov bh,00
mov dh,09h
mov dl,b
int 10h
mov ah,09h
lea dx,str
int 21h
mov ax,600h
mov bh,61h
mov cx,0a00h
mov dx,0aaah
int 10h
mov ax,600h
mov bh,30h
mov ch,a
mov cl,b
mov dh,c
mov dl,d
int 10h
mov ch,07h
mov cl,e
mov dl,f
int 10h
inc b
inc d
inc e
inc f
call delay
cmp ctr,60
jne pawan
mov ah,4ch
int 21h
main endp


delay proc near
mov ah,00h
int 1ah
mov tik,dx
add tik,1h
b10:
mov ah,00h
int 1ah
cmp tik,dx
jge b10

ret
delay endp

end main

Saturday, March 15, 2014

color change of screen in 8086

color change of screen if press 1
.model small
.stack 64
.data
clor db 10h
.code
main proc near

mov ax,@data
mov ds,ax

mov ax,3h           ; clear screen
int 10h

a10:
mov ax,0600h         ;set disply
mov bh,clor
mov cx,0000h           ; x1,y1
mov dx,184fh             ;x2,y2
int 10h
add clor,10h                  ;change background color

mov ah,8h                  ; ikeyboard nput
int 21h
cmp al,'1'                      ; if 1 press then color change otherwise exit
je a10

mov ax,4c00h
int 21h

main endp
end main

moving screen box in 8086

.model small
.stack 64
.data
point1a dw 510h
point1b dw 1520h      ;coordinate of box
tik dw ?
.386
.code
main proc near

mov ax,@data
mov ds,ax



a10:
mov ax,0600h          ;set disply
mov bh,52h              ; 5 background color ,2 forehead color
mov cx,point1a          ; x1, y1
mov dx,point1b           ;x2, y2
int 10h

call delay                      ;delay of 1 sec

inc point1a                 ; move point forward for   next disply
inc point1b
mov dl,cl                
mov ax,0600h            ; erase starting row of box
mov bh,00h
int 10h

cmp cl,63          
jb a10


mov ax,4c00h
int 21h
main endp

delay proc near

pusha


mov ah,00h         ;give system time
int 1ah

mov tik,dx           ;in dx  
add tik,12h         ; store in tik  (1 sec= 12h value)  ,system time+1sec
b10:
mov ah,00h
int 1ah

cmp tik,dx            ;execute loop until 1sec over
jge b10

popa
ret
 delay endp
end main

Contributors

Translate