Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .MODEL Small
- .CODE
- org 100h
- Jmp Start
- st dw 100
- y2 dw 120
- x2 dw 120
- on dw 100
- ent db 13, 13, 13, 10, '$'
- Color db 4 ; mau do
- hcnd db 'Nhap do dai canh doc: $'
- hcnn db 'Nhap do dai canh ngang: $'
- tgc db 'Nhap do dai chieu cao: $'
- th db 'Nhap do dai duong cheo: $'
- Start:
- Mov AH,0h ; thiet lap che do do hoa
- Mov AL,12h ; VGA mode
- Int 10h
- ; Nhap so de xac dinh loai hinh can ve
- Mov AX, 0
- Mov AH, 1; Cho 1 phim go vao
- Int 21h
- Push AX
- Mov AH, 9
- Lea DX, ent; in ra ent (xuong dong)
- Int 21H
- Mov AX, 0
- Pop AX
- Cmp AL, '1'
- Je RE ; Neu bang 1, nhay den nhan RE de ve hinh chu nhat hoac vuong
- Cmp AL, '2'
- Je TRI ; Neu bang 2, nhay den nhan TRI de ve hinh tam giac
- Cmp AL, '3'
- Je RHOM ; Neu bang 3, nhay den nhan RHOM de ve hinh thoi
- Cmp AL, '#'
- Je END ; Neu bang #, nhay den nhan END de ket thuc chuong trinh
- Jmp Start
- RE:
- Call Rectangle
- Jmp Start
- TRI:
- Call Triangle
- Jmp Start
- RHOM:
- Call Rhombus
- Jmp Start
- ;Ve hinh chu nhat
- Rectangle Proc
- Mov AH, 9
- Lea DX, hcnd
- Int 21H
- Call input ; Nhap chieu cao
- Mov y2, AX
- Add y2, 100
- Mov AH, 9
- Lea DX, hcnn
- Int 21H
- Call input ; Nhap chieu ngang
- Mov x2, AX
- Add x2, 100
- Mov CX,x2 ; CX = x2 - st = do dai canh
- Sub CX,st
- Mov SI,st ; SI: bien dem theo chieu cao
- Mov DI,st ; DI: bien dem theo chieu ngang
- ; Ve canh tren
- TopR:
- Call DrawPixel ; goi chuong trinh con ve diem anh
- Inc DI ;
- Loop TopR
- Mov CX, y2
- Sub CX, st
- Mov SI, st
- ; Ve canh 2 canh ben
- SideR:
- Mov DI, st
- Call DrawPixel
- Mov DI, x2
- Call DrawPixel
- Inc SI
- Loop SideR
- Mov CX, x2
- Sub CX, st
- Mov SI, y2
- Mov DI, st
- ; Ve canh duoi
- BotR:
- Call DrawPixel
- Inc DI ;
- Loop BotR
- mov ah, 8; Tam dung man hinh de xem hinh
- int 21h
- Mov AH,0 ; Set video mode
- Mov AL,2
- Int 10h
- Ret
- Rectangle Endp
- ;Ve hinh tam giac
- Triangle Proc
- Mov st, 100
- Mov x2, 100
- Mov AH, 9
- Lea DX, tgc
- Int 21H
- Call input
- Mov y2, AX
- Add y2, 100
- Mov CX, y2
- Sub CX, st
- Mov SI, st
- ;Ve 2 canh ben
- SideT:
- Mov DI, st
- Sub st, 1
- Call DrawPixel
- Mov DI, x2
- Add x2, 1
- Call DrawPixel
- Inc SI
- Loop SideT
- Mov CX, x2
- Sub CX, st
- Mov SI, y2
- Mov DI, st
- ; Ve canh duoi
- BotT:
- Call DrawPixel
- Inc DI ;
- Loop BotT
- Mov ah, 8
- Int 21h
- Mov AH,0
- Mov AL,2
- Int 10h
- Ret
- Triangle Endp
- ;Ve hinh thoi
- Rhombus proc
- Mov st, 100
- Mov x2, 100
- Mov AH, 9
- Lea DX, th
- Int 21H
- Call input
- Mov y2, AX
- Add y2, 100
- Mov CX, y2
- Sub CX, st
- Mov SI, st
- ;Ve 2 canh ben tren
- TopSideRH:
- Mov DI, st
- Sub st, 1
- Call DrawPixel
- Mov DI, x2
- Add x2, 1
- Call DrawPixel
- Inc SI
- Loop TopSideRH
- Mov CX, on
- Sub CX, st
- Add CX, 1
- ; Ve 2 canh ben duoi
- BotSideRH:
- Mov DI,st
- Add st, 1
- Call DrawPixel
- Mov DI, x2
- Sub x2, 1
- Call DrawPixel
- Inc SI
- Loop BotSideRH
- mov ah, 8
- int 21h
- Mov AH,0
- Mov AL,2
- Int 10h
- Ret
- Rhombus Endp
- ;To mau 1 pixel
- DrawPixel Proc
- Push AX
- Push CX
- Push DX
- Mov DX, SI
- Mov CX,DI
- Mov AL, Color
- Mov AH,0CH
- Int 10h
- Pop DX
- Pop CX
- Pop AX
- Ret
- DrawPixel Endp
- ; Nhap vao 1 so tu nhien
- input Proc
- Push bx
- Push cx
- Push dx
- STA:
- Mov ah, 2
- Xor bx, bx
- Xor cx, cx
- Mov ah, 1
- Int 21h
- Cmp al, '-'
- Je SUBT
- Cmp al, '+'
- Je ADDN
- Jmp CON
- SUBT:
- Mov cx, 1
- ADDN:
- Int 21h
- CON:
- Cmp al, '0'
- Jnge NOTN ; khong lop hon hoac bang
- Cmp al, '9'
- Jnle NOTN ; Khong nho hon hoac bang
- And ax, 000fh ; doi thanh chu so
- Push ax ; cat vao ngan xep
- Mov ax, 10
- Mul bx ; ax = tong*10
- Mov bx, ax
- Pop ax
- Add bx, ax ; tong = tong*10 + so
- Mov ah, 1
- Int 21h
- Cmp al, 13 ; da enter chua?
- Jne CON ; nhap tiep
- Mov ax, bx ; chuyen KQ ra ax
- Or cx, cx ; co phai so am khong
- Je O
- Neg ax ; neu la so am thi doi ax ra so am
- O:
- Pop dx
- Pop cx
- Pop bx
- Ret
- NOTN:
- Mov ah, 2
- Mov dl, 0dh
- Int 21h
- Mov dl, 0ah
- Int 21
- Jmp STA
- Ret
- input Endp
- END:
- Mov ah, 4CH
- Int 21h
- End Start
Add Comment
Please, Sign In to add comment