; array1.asm
.286
.model small
.stack
.data
demo db 'Array1 Version 1.0 Copyright(c) 1994 by Brent Su.$'
arr1 db 'Array[$'
arr2 db '] = $'
sum db 'Sum (array) = $'
array1 dw 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
anser dw ?
numstr db 80 dup(0)
; Assembly Function
.code
clrscr proc
pusha
mov al,0
mov bh,07H
mov cx,0
mov dh,24
mov dl,79
mov ah,06H
int 10H
mov dx,0
mov bh,0
mov ah,02H
int 10H
popa
ret
clrscr endp
printstr proc
push ax
mov ah,09H
int 21H
pop ax
ret
printstr endp
printchar proc
push ax
mov ah,02H
int 21H
pop ax
ret
printchar endp
printline proc
pusha
mov ah,09H
int 21H
mov dl,10
call printchar
mov dl,13
call printchar
popa
ret
printline endp
prnnewline proc
push dx
mov dl,10
call printchar
mov dl,13
call printchar
pop dx
ret
prnnewline endp
itoa proc
pusha
mov cx,0
mov bx,10
@@divide:
mov dx,0
div bx
push dx
inc cx
cmp ax,0
jnz @@divide
lea bx,numstr
@@output:
pop ax
add al,48
mov [bx],al
inc bx
loop @@output
mov byte ptr [bx],'$'
popa
ret
itoa endp
printint proc
push dx
call itoa
lea dx,numstr
call printstr
pop dx
ret
printint endp
; main program
.code
start:
mov ax,@data
mov ds,ax
call clrscr
lea dx,demo
call printline
mov cx,10
lea bx,array1
mov ax,0
@@_for:
add ax,[bx]
add bx,2
loop @@_for
mov anser,ax
mov cx,10
lea bx,array1
mov di,1
@@_print:
lea dx,arr1
call printstr
mov ax,di
call printint
lea dx,arr2
call printstr
mov ax,[bx]
call printint
call prnnewline
inc di
add bx,2
loop @@_print
lea dx,sum
call printstr
mov ax,anser
call printint
call prnnewline
mov ax,4c00H
int 21H
end start
; array2.asm
.286
.model small
.stack
.data
demo db 'Array2 program Version 1.0 Copyright(c) 1994 by Jackie Su.$'
strlen db 0
strsize db 0
string db 256 dup(0)
arr0 db 'Input Array[$'
arr1 db 'Array[$'
arr2 db '] = $'
sum db 'Sum (array) = $'
array1 dw 10 dup(0)
anser dw ?
numstr db 80 dup(0)
tonum dw 0
; Assembly Function
.code
clrscr proc
pusha
mov al,0
mov bh,07H
mov cx,0
mov dh,24
mov dl,79
mov ah,06H
int 10H
mov dx,0
mov bh,0
mov ah,02H
int 10H
popa
ret
clrscr endp
printstr proc
push ax
mov ah,09H
int 21H
pop ax
ret
printstr endp
printchar proc
push ax
mov ah,02H
int 21H
pop ax
ret
printchar endp
printline proc
pusha
mov ah,09H
int 21H
mov dl,10
call printchar
mov dl,13
call printchar
popa
ret
printline endp
prnnewline proc
push dx
mov dl,10
call printchar
mov dl,13
call printchar
pop dx
ret
prnnewline endp
inputstr proc
pusha
mov ah,0aH
int 21H
mov bx,dx
mov dx,0
inc bx
mov dl,[bx]
add bx,dx
inc bx
mov byte ptr[bx],'$'
popa
ret
inputstr endp
itoa proc
pusha
mov cx,0
mov bx,10
@@divide:
mov dx,0
div bx
push dx
inc cx
cmp ax,0
jnz @@divide
lea bx,numstr
@@output:
pop ax
add al,48
mov [bx],al
inc bx
loop @@output
mov byte ptr [bx],'$'
popa
ret
itoa endp
htoa proc
pusha
mov cx,4
@@convert:
mov dx,ax
and dx,000fH
push dx
shr ax,4
loop @@convert
mov cx,4
lea bx,numstr
@@output2:
pop ax
cmp al,10
jae @@hex2
add al,48
jmp @@out2
@@hex2:
add al,55
@@out2:
mov [bx],al
inc bx
loop @@output2
mov byte ptr [bx],'$'
popa
ret
htoa endp
btoa proc
pusha
mov cx,16
@@convert3:
mov dx,ax
and dx,0001H
push dx
shr ax,1
loop @@convert3
mov cx,16
lea bx,numstr
@@output3:
pop ax
add al,48
mov [bx],al
inc bx
loop @@output3
mov byte ptr [bx],'$'
popa
ret
btoa endp
atoi proc
pusha
mov bx,dx
mov di,0
mov si,0
mov ax,0
mov tonum,0
cmp byte ptr [bx],'-'
jne @@getchar1
mov di,1
inc bx
@@getchar1:
mov al,[bx]
cmp al,'$'
je @@getok1
sub al,48
push ax
inc bx
inc si
jmp @@getchar1
@@getok1:
cmp si,0
jz @@exit1
mov cx,1
mov bx,10
@@multipli:
pop ax
mul cx
add tonum,ax
mov ax,cx
mul bx
mov cx,ax
dec si
jnz @@multipli
cmp di,0
jz @@exit1
neg tonum
@@exit1:
popa
ret
atoi endp
printint proc
push dx
call itoa
lea dx,numstr
call printstr
pop dx
ret
printint endp
printhex proc
push dx
call htoa
lea dx,numstr
call printstr
pop dx
ret
printhex endp
printbin proc
push dx
call btoa
lea dx,numstr
call printstr
pop dx
ret
printbin endp
; main program
.code
start:
mov ax,@data
mov ds,ax
call clrscr
lea dx,demo
call printline
mov strlen,5
mov cx,10
mov di,1
lea bx,array1
@@_for:
lea dx,arr0
call printstr
mov ax,di
call printint
lea dx,arr2
call printstr
lea dx,strlen
call inputstr
call prnnewline
lea dx,string
call atoi
mov ax,tonum
mov [bx],ax
add bx,2
inc di
loop @@_for
mov cx,10
lea bx,array1
mov ax,0
@@_for1:
add ax,[bx]
add bx,2
loop @@_for1
mov anser,ax
mov cx,10
lea bx,array1
mov di,1
@@_print:
lea dx,arr1
call printstr
mov ax,di
call printint
lea dx,arr2
call printstr
mov ax,[bx]
call printint
call prnnewline
inc di
add bx,2
loop @@_print
lea dx,sum
call printstr
mov ax,anser
call printint
call prnnewline
mov ax,4c00H
int 21H
end start