Wednesday, June 23, 2010

Sorting numbers in descending order

Buzz It
#make_COM#
; COM file is loaded at CS:0100h
ORG 100h
mov cl,[2200h]
mov bh,cl
cont:mov bp,2201h
mov cl,bh
zz:mov ah,[bp]
inc bp
cmp ah,[bp]
jnb xx
xchg ah,[bp]
xchg ah,[bp-1]
xx:loop zz
dec bh
jnz cont
hlt

Input
[2200H]=5
[2201H]=4
[2202H]=9
[2203H]=5
[2204H]=11
[2205H]=2

Output
[2201H]=11
[2202H]=9
[2203H]=5
[2204H]=4
[2205H]=2

Sorting numbers in ascending order

Buzz It
#make_COM#
; COM file is loaded at CS:0100h
ORG 100h
mov cl,[2200h]
mov bh,cl
cont:mov bp,2201h
mov cl,bh
zz:mov ah,[bp]
inc bp
cmp ah,[bp]
jb xx
xchg ah,[bp]
xchg ah,[bp-1]
xx:loop zz
dec bh
jnz cont
hlt


Input
[2200H]=5
[2201H]=4
[2202H]=9
[2203H]=5
[2204H]=11
[2205H]=2

Output
[2201H]=2
[2202H]=4
[2203H]=5
[2204H]=9
[2205H]=11

Smallest

Buzz It
#make_COM#
; COM file is loaded at CS:0100h
ORG 100h
mov si,3000h
mov cx,05h
mov al,[3000h]
xx:cmp al,[si]
jle go
mov al,[si]
go:inc si
loop xx
mov [3009h],al
hlt

Input
[3000H]=01
[3002H]=02
[3003H]=03
[3004H]=04
[3005H]=05

Output
[3009H]=01

Factorial

Buzz It
#make_COM#
; COM file is loaded at CS:0100h
ORG 100h
mov bx,[2000h]
mov ax,01h
mov cx,bx
xx:mul cx
loop xx
mov [2002h],ax
mov [2004h],dx
hlt

Input
[2000H]=05

Output
[2002H]=78

Largest element

Buzz It
#make_COM#
;COM file is loaded at CS:0100h
ORG 100h
mov si,3000h
mov cx,05h
mov ax,[3000h]
inc si
xx:add ax,[si]
inc si
loop xx
mov [3009h],ax
hlt


Input
[3000H]=01
[3002H]=02
[3003H]=03
[3004H]=04
[3005H]=05

Output
[3009H]=05

Sum of elements in an array

Buzz It
#make_COM#
;COM file is loaded at CS:0100h
ORG 100h
mov si,3000h
mov cx,05h
mov ax,[3000h]
inc si
xx:add ax,[si]
inc si
loop xx
mov [3009h],ax
hlt

Input
[3000H]=01
[3002H]=02
[3003H]=03
[3004H]=04
[3005H]=05

Output
[3009H]=0F

32 subtraction

Buzz It
#make_COM#
; COM file is loaded at CS:0100h
ORG 100h
MOV AX,[2000H]
MOV BX,[2002H]
MOV CX,[2004H]
MOV DX,[2006H]
SUB AX,CX
SUB BX,DX
MOV [2008H],AX
MOV [200AH],BX
HLT


Input
[2000H]=04
[2001H]=04
[2002H]=04
[2003H]=04
[2004H]=03
[2005H]=03
[2006H]=03
[2007H]=03


Output
[2008H]=01
[2009H]=01
[200AH]=01
[200BH]=01


32 bit addition

Buzz It
#make_COM#
; COM file is loaded at CS:0100h
ORG 100h
MOV AX,[2000H]
MOV BX,[2002H]
MOV CX,[2004H]
MOV DX,[2006H]
ADD AX,CX
ADD BX,DX
MOV [2008H],AX
MOV [200AH],BX
HLT


Input
[2000H]=04
[2001H]=04
[2002H]=04
[2003H]=04
[2004H]=03
[2005H]=03
[2006H]=03
[2007H]=03


Output
[2008H]=07
[2009H]=07
[200AH]=07
[200BH]=07

16 bit division

Buzz It
#make_COM#
; COM file is loaded at CS:0100h
ORG 100h
mov ax,[2000h]
mov bx,[2002h]
div bx
mov [2004h],ax
mov [2006h],dx
hlt

Input
[2000H]=00
[2001H]=02
[2002H]=00
[2003H]=02


Output
[2004H]=01
[2005H]=00
[2006H]=00
[2007H]= 00

16 bit multiplication

Buzz It
#make_COM#
; COM file is loaded at CS:0100h
ORG 100h
mov ax,[2000h]
mov bx,[2002h]
mul bx
mov [2004h],ax
mov [2006h],dx
hlt


Input
[2000H]=10
[2001H]=00
[2002H]=50
[2003H]=00

Output
[2004H]=00
[2005H]=05
[2006H]=00
[2007H]=00

16 bit Subtraction

Buzz It
#make_COM#
; COM file is loaded at CS:0100h
ORG 100h
mov ax,[2000h]
mov bx,[2002h]
sub ax,bx
mov [2004h],ax
hlt

Input
[2000H]=00
[2001H]=02
[2002H]=50
[2003H]=02


Output
[2004H]=50
[2005H]=00

16 bit Addition

Buzz It

#make_COM#
; COM file is loaded at CS:0100h
ORG 100h
mov ax,[2000h]
mov bx,[2002h]
add ax,bx
mov [2004h],ax
hlt

Input
[2000H]=00
[2001H]=01
[2002H]=50
[2003H]=02


Output
[2004H]=50
[2005H]=03

8 bit multiplication

Buzz It
#make_COM#
; COM file is loaded at CS:0100h
ORG 100h
mov al,[1000h]
mov bl,[1001h]
mul bl
mov [1003h],al
hlt
Input
[1000H]=02
[1001H]=02
Output
[1003H]=04