├── cover.jpg ├── Lab10 ├── proj1.png ├── lab10_1.png ├── lab10_2.png ├── lab10_3.png ├── lab10_3r.png ├── lab10_1.asm ├── lab10_2.asm ├── lab10_3.asm └── lab10_3r.asm ├── Lab11 ├── lab11.png └── lab11.asm ├── Lab14 ├── lab14.png └── lab14.asm ├── Lab15 ├── lab15.gif └── lab15.asm ├── Lab9 ├── lab9.png └── lab9.asm ├── Project1 ├── proj1.png └── proj1.asm ├── README.md ├── Lab4 ├── lab4_3.asm └── lab4_1_2.asm ├── Checkpoints ├── chk9_2.asm ├── chk14_1.asm ├── chk14_2.asm └── chk13_1.asm ├── Lab5 ├── lab5_2.asm ├── lab5_3.asm ├── lab5_5.asm ├── lab5_1.asm └── lab5_4.asm ├── Lab6 └── prob7_9.asm ├── Lab13 ├── lab13_3.asm ├── lab13_2.asm └── lab13_1.asm ├── LICENSE ├── Lab12 └── lab12.asm ├── Lab8 └── lab8.asm └── Lab7 └── lab7.asm /cover.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/richardhyy/AssemblyLab/HEAD/cover.jpg -------------------------------------------------------------------------------- /Lab10/proj1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/richardhyy/AssemblyLab/HEAD/Lab10/proj1.png -------------------------------------------------------------------------------- /Lab11/lab11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/richardhyy/AssemblyLab/HEAD/Lab11/lab11.png -------------------------------------------------------------------------------- /Lab14/lab14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/richardhyy/AssemblyLab/HEAD/Lab14/lab14.png -------------------------------------------------------------------------------- /Lab15/lab15.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/richardhyy/AssemblyLab/HEAD/Lab15/lab15.gif -------------------------------------------------------------------------------- /Lab9/lab9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/richardhyy/AssemblyLab/HEAD/Lab9/lab9.png -------------------------------------------------------------------------------- /Lab10/lab10_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/richardhyy/AssemblyLab/HEAD/Lab10/lab10_1.png -------------------------------------------------------------------------------- /Lab10/lab10_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/richardhyy/AssemblyLab/HEAD/Lab10/lab10_2.png -------------------------------------------------------------------------------- /Lab10/lab10_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/richardhyy/AssemblyLab/HEAD/Lab10/lab10_3.png -------------------------------------------------------------------------------- /Lab10/lab10_3r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/richardhyy/AssemblyLab/HEAD/Lab10/lab10_3r.png -------------------------------------------------------------------------------- /Project1/proj1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/richardhyy/AssemblyLab/HEAD/Project1/proj1.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AssemblyLab 2 | Assembly (4th Edition) - WangShuang - Labs 3 | 4 | ![cover](cover.jpg) -------------------------------------------------------------------------------- /Lab4/lab4_3.asm: -------------------------------------------------------------------------------- 1 | assume cs:code 2 | code segment 3 | 4 | mov ax,cs 5 | mov ds,ax 6 | mov ax,0020h 7 | mov es,ax 8 | mov bx,0 9 | mov cx,16h 10 | 11 | s: mov al,[bx] 12 | mov es:[bx],al 13 | inc bx 14 | loop s 15 | 16 | mov ax,4c00h 17 | int 21h 18 | 19 | code ends 20 | 21 | end -------------------------------------------------------------------------------- /Checkpoints/chk9_2.asm: -------------------------------------------------------------------------------- 1 | assume cs:code 2 | data segment 3 | dd 1,2,3,4 4 | data ends 5 | 6 | code segment 7 | start: mov ax,2000H 8 | mov ds,ax 9 | mov bx,0 10 | s: mov cl,0 11 | mov ch,[bx] 12 | jcxz ok 13 | inc bx 14 | jmp short s 15 | ok: mov dx,bx 16 | mov ax,4c00h 17 | int 21h 18 | code ends 19 | end start -------------------------------------------------------------------------------- /Lab4/lab4_1_2.asm: -------------------------------------------------------------------------------- 1 | assume cs:code 2 | 3 | code segment 4 | 5 | mov ax,0020h ;1 6 | mov ds,ax ;2 7 | 8 | mov bx,0040h ;3 9 | s: sub bl,1 ;4 10 | mov [bx],bl ;5 11 | 12 | loop s ;6 13 | 14 | mov ax,4c00h ;7 15 | int 21h ;8 16 | 17 | code ends 18 | 19 | end 20 | -------------------------------------------------------------------------------- /Lab5/lab5_2.asm: -------------------------------------------------------------------------------- 1 | assume cs:code,ds:data,ss:stack 2 | 3 | data segment 4 | dw 0123H,0456H 5 | data ends 6 | 7 | stack segment 8 | dw 0,0 9 | stack ends 10 | 11 | code segment 12 | 13 | start: mov ax,stack 14 | mov ss,ax 15 | mov sp,16 16 | 17 | mov ax,data 18 | mov ds,ax 19 | 20 | push ds:[0] 21 | push ds:[2] 22 | pop ds:[2] 23 | pop ds:[0] 24 | 25 | mov ax,4c00h 26 | int 21h 27 | 28 | code ends 29 | 30 | end start -------------------------------------------------------------------------------- /Lab5/lab5_3.asm: -------------------------------------------------------------------------------- 1 | assume cs:code,ds:data,ss:stack 2 | 3 | code segment 4 | 5 | start: mov ax,stack 6 | mov ss,ax 7 | mov sp,16 8 | 9 | mov ax,data 10 | mov ds,ax 11 | 12 | push ds:[0] 13 | push ds:[2] 14 | pop ds:[2] 15 | pop ds:[0] 16 | 17 | mov ax,4c00h 18 | int 21h 19 | 20 | code ends 21 | 22 | data segment 23 | dw 0123H,0456H 24 | data ends 25 | 26 | stack segment 27 | dw 0,0 28 | stack ends 29 | 30 | end start -------------------------------------------------------------------------------- /Lab5/lab5_5.asm: -------------------------------------------------------------------------------- 1 | assume cs:code 2 | 3 | a segment 4 | dw 1,2,3,4,5,6,7,8,9,0ah,0bh,0ch,0dh,0eh,0fh,0ffh 5 | a ends 6 | 7 | b segment 8 | dw 0,0,0,0,0,0,0,0 9 | b ends 10 | 11 | code segment 12 | start: mov ax,b 13 | mov ss,ax 14 | mov sp,010h 15 | mov ax,a 16 | mov ds,ax 17 | mov cx,8 18 | mov bx,0 19 | 20 | s: push [bx] 21 | add bx,2 22 | loop s 23 | 24 | mov ax,4c00h 25 | int 21h 26 | code ends 27 | 28 | end start -------------------------------------------------------------------------------- /Checkpoints/chk14_1.asm: -------------------------------------------------------------------------------- 1 | assume cs:code 2 | code segment 3 | start: ; Checkpoint 14.1 (1) 4 | ; Read from the #2 unit of CMOS RAM 5 | mov dx,70h 6 | mov al,2 7 | out dx,al 8 | mov dx,71h 9 | in al,dx 10 | 11 | ; Checkpoint 14.1 (2) 12 | ; Write 0 to the #2 unit of CMOS RAM 13 | mov dx,70h 14 | mov al,2 15 | out dx,al 16 | mov dx,71h 17 | mov al,0 18 | out dx,al 19 | 20 | mov ax,4c00h 21 | int 21h 22 | code ends 23 | end start -------------------------------------------------------------------------------- /Checkpoints/chk14_2.asm: -------------------------------------------------------------------------------- 1 | assume cs:code 2 | code segment 3 | start: ; Checkpoint 14.2 4 | ; Evaluate: (ax)=(ax)*10 5 | mov ax,42 6 | call t10 7 | 8 | mov ax,4c00h 9 | int 21h 10 | 11 | t10:push bx 12 | push cx 13 | 14 | mov bx,ax ; (bx)=(ax) 15 | shl ax,1 ; (ax)*2 16 | 17 | mov cl,3 18 | shl bx,cl ; (ax)*8 19 | 20 | add ax,bx ; (ax)=(ax)+(bx) 21 | 22 | pop cx 23 | pop bx 24 | ret 25 | 26 | code ends 27 | end start -------------------------------------------------------------------------------- /Lab5/lab5_1.asm: -------------------------------------------------------------------------------- 1 | assume cs:code,ds:data,ss:stack 2 | 3 | data segment 4 | dw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h 5 | data ends 6 | 7 | stack segment 8 | dw 0,0,0,0,0,0,0,0 9 | stack ends 10 | 11 | code segment 12 | 13 | start: mov ax,stack 14 | mov ss,ax 15 | mov sp,16 16 | 17 | mov ax,data 18 | mov ds,ax 19 | 20 | push ds:[0] 21 | push ds:[2] 22 | pop ds:[2] 23 | pop ds:[0] 24 | 25 | mov ax,4c00h 26 | int 21h 27 | 28 | code ends 29 | 30 | end start -------------------------------------------------------------------------------- /Lab5/lab5_4.asm: -------------------------------------------------------------------------------- 1 | assume cs:code 2 | 3 | a segment 4 | db 1,2,3,4,5,6,7,8 5 | a ends 6 | 7 | b segment 8 | db 1,2,3,4,5,6,7,8 9 | b ends 10 | 11 | c segment 12 | db 0,0,0,0,0,0,0,0 13 | c ends 14 | 15 | code segment 16 | start: mov ax,a 17 | mov ds,ax 18 | mov ax,b 19 | mov es,ax 20 | mov ax,c 21 | mov ss,ax 22 | mov cx,8 23 | s: mov bx,cx 24 | sub bx,1 25 | mov dl,[bx] 26 | add dl,es:[bx] 27 | mov ss:[bx],dl 28 | loop s 29 | mov ax,4c00h 30 | int 21h 31 | code ends 32 | end start 33 | -------------------------------------------------------------------------------- /Lab6/prob7_9.asm: -------------------------------------------------------------------------------- 1 | assume cs:codesg,ss:stacksg,ds:datasg 2 | 3 | stacksg segment 4 | dw 0,0,0,0,0,0,0,0 5 | stacksg ends 6 | 7 | datasg segment 8 | db '1. display ' 9 | db '2. brows ' 10 | db '3. replace ' 11 | db '4. modify ' 12 | datasg ends 13 | 14 | codesg segment 15 | start: mov ax,datasg 16 | mov ds,ax 17 | mov ax,stacksg 18 | mov ss,ax 19 | mov sp,10H 20 | mov bx,3 21 | mov cx,4 22 | 23 | s: push cx 24 | mov si,0 25 | mov cx,4 26 | 27 | s1: mov al,[bx][si] 28 | and al,11011111b 29 | mov [bx][si],al 30 | inc si 31 | loop s1 32 | 33 | add bx,16 34 | pop cx 35 | loop s 36 | 37 | mov ax,4c00H 38 | int 21H 39 | codesg ends 40 | end start -------------------------------------------------------------------------------- /Lab13/lab13_3.asm: -------------------------------------------------------------------------------- 1 | assume cs:code 2 | code segment 3 | s1: db 'Good,better,best,','$' 4 | s2: db 'Never let it rest,','$' 5 | s3: db 'Till good is better,','$' 6 | s4: db 'And better,best.','$' 7 | s : dw offset s1,offset s2,offset s3,offset s4 8 | row:db 2,4,6,8 9 | 10 | start: mov ax,cs 11 | mov ds,ax 12 | mov bx,offset s 13 | mov si,offset row 14 | mov cx,4 15 | ok: mov bh,0 16 | mov dh,ds:[si] ; blank filled 17 | mov dl,0 18 | mov ah,2 19 | int 10h 20 | 21 | mov dx,ds:[bx] ; blank filled 22 | mov ah,9 23 | int 21h 24 | 25 | add bx,2 ; blank filled 26 | add si,1 ; blank filled 27 | loop ok 28 | 29 | mov ax,4c00h 30 | int 21h 31 | code ends 32 | end start -------------------------------------------------------------------------------- /Lab9/lab9.asm: -------------------------------------------------------------------------------- 1 | assume cs:codesg 2 | 3 | data segment 4 | db 'welcome to masm!' 5 | db 00000010b,00100100b,01110001b 6 | data ends 7 | 8 | stack segment 9 | dd 0,0 10 | stack ends 11 | 12 | codesg segment 13 | start: mov ax,data 14 | mov ds,ax 15 | 16 | mov ax,0B800H 17 | mov es,ax 18 | mov di,0780H 19 | add di,20H ; center the output 20 | 21 | mov ax,stack 22 | mov ss,ax 23 | mov sp,10H 24 | 25 | mov si,0 ; color offset 26 | mov bp,0 27 | 28 | mov cx,3 29 | s: push cx 30 | mov bx,0 ; text offset 31 | mov cx,16 32 | s1: mov al,ds:[bx] 33 | mov es:[bp+di],al 34 | mov al,ds:[10H+si] ; color 35 | mov es:[bp+di+1],al 36 | add bp,2 37 | inc bx 38 | loop s1 39 | 40 | inc si 41 | pop cx 42 | loop s 43 | 44 | mov ax,4c00H 45 | int 21h 46 | codesg ends 47 | 48 | end start -------------------------------------------------------------------------------- /Lab11/lab11.asm: -------------------------------------------------------------------------------- 1 | ; Lab 11 2 | ; name: letterc 3 | ; func: Convert a string of characters ends with 0 to upper case. 4 | ; args: di:si : points to the beginning of the string 5 | 6 | assume cs:codesg 7 | 8 | datasg segment 9 | db "Beginner's All-purpose Symbolic Instruction Code.",0 10 | datasg ends 11 | 12 | stacksg segment 13 | dd 0,0 14 | stacksg ends 15 | 16 | codesg segment 17 | begin: mov ax,datasg 18 | mov ds,ax 19 | mov si,0 20 | call letterc 21 | 22 | mov ax,4c00h 23 | int 21h 24 | 25 | letterc:push cx 26 | push si 27 | 28 | mov cx,0 29 | 30 | l_upper:cmp byte ptr [si],97 ; if (si)<'a' 31 | jb l_next 32 | cmp byte ptr [si],122 ; if (si)>'z' 33 | ja l_next 34 | and byte ptr [si],11011111b 35 | 36 | l_next: inc si 37 | mov cl,[si] 38 | jcxz l_done ; stop at \0 39 | jmp short l_upper 40 | 41 | l_done: pop si 42 | pop cx 43 | ret 44 | codesg ends 45 | 46 | end begin -------------------------------------------------------------------------------- /Checkpoints/chk13_1.asm: -------------------------------------------------------------------------------- 1 | assume cs:code 2 | data segment 3 | db 'Light and Wings',0 4 | data ends 5 | 6 | code segment 7 | start: call setjpn 8 | 9 | mov ax,data 10 | mov ds,ax 11 | mov si,0 12 | mov ax,0b800h 13 | mov es,ax 14 | mov di,12*160 15 | s: cmp byte ptr [si],0 16 | je ok 17 | mov al,[si] 18 | mov es:[di],al 19 | inc si 20 | add di,2 21 | mov bx,offset s-offset ok 22 | int 7ch 23 | ok: mov ax,4c00h 24 | int 21h 25 | 26 | ; Set up jpn 27 | setjpn:mov ax,cs 28 | mov ds,ax 29 | mov si,offset jpn 30 | mov ax,0 31 | mov es,ax 32 | mov di,200h 33 | mov cx,offset jpnend-offset jpn 34 | cld 35 | rep movsb 36 | 37 | mov ax,0 38 | mov es,ax 39 | mov word ptr es:[7ch*4],200h 40 | mov word ptr es:[7ch*4+2],0 41 | ret 42 | 43 | jpn:push bp 44 | mov bp,sp 45 | add [bp+2],bx 46 | pop bp 47 | iret 48 | jpnend:nop 49 | 50 | code ends 51 | end start 52 | -------------------------------------------------------------------------------- /Lab15/lab15.asm: -------------------------------------------------------------------------------- 1 | assume cs:code 2 | 3 | stack segment 4 | db 128 dup (0) 5 | stack ends 6 | 7 | code segment 8 | start: mov ax,stack 9 | mov ss,ax 10 | mov sp,128 11 | 12 | push cs 13 | pop ds 14 | 15 | mov ax,0 16 | mov es,ax 17 | 18 | mov si,offset int9 19 | mov di,204h 20 | mov cx,offset int9end-offset int9 21 | cld 22 | rep movsb 23 | 24 | push es:[9*4] 25 | pop es:[200h] 26 | push es:[9*4+2] 27 | pop es:[202h] 28 | 29 | cli 30 | mov word ptr es:[9*4],204h 31 | mov word ptr es:[9*4+2],0 32 | sti 33 | 34 | mov ax,4c00h 35 | int 21h 36 | 37 | int9: push ax 38 | push bx 39 | push cx 40 | push es 41 | 42 | in al,60h 43 | 44 | pushf 45 | call dword ptr cs:[200h] 46 | 47 | cmp al,9Eh ; A released (1E+80) 48 | jne int9ret 49 | 50 | mov ax,0b800h 51 | mov es,ax 52 | mov bx,0 53 | mov cx,2000 54 | s: mov byte ptr es:[bx],'A' 55 | add bx,2 56 | loop s 57 | 58 | int9ret:pop es 59 | pop cx 60 | pop bx 61 | pop ax 62 | iret 63 | 64 | int9end:nop 65 | 66 | code ends 67 | end start -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Alan_Richard 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Lab12/lab12.asm: -------------------------------------------------------------------------------- 1 | assume cs:code 2 | code segment 3 | start: ; Set Up the Interruption Handler 4 | mov ax,cs 5 | mov ds,ax 6 | mov si,offset do0 7 | mov ax,0 8 | mov es,ax 9 | mov di,200h 10 | 11 | mov cx,offset do0end-offset do0 12 | ; w/o offset: 0B28:000F B92D00 MOV CX,002D 13 | ; w/ offset: 0B28:000F B92D00 MOV CX,002D 14 | 15 | cld 16 | rep movsb 17 | 18 | ; Set Interruption Vector Table 19 | mov ax,0 20 | mov es,ax 21 | mov word ptr es:[0*4],200h ; offset 22 | mov word ptr es:[0*4+2],0 ; segment 23 | 24 | ; Test the Handler 25 | mov ax,1000h 26 | mov bh,1 27 | div bh 28 | 29 | mov ax,4c00h 30 | int 21h 31 | 32 | ; Interruption Handler 33 | do0: jmp short do0start 34 | db "overflow!" 35 | do0start:mov ax,cs 36 | mov ds,ax 37 | mov si,202h ; points to the text 38 | 39 | mov ax,0b800h 40 | mov es,ax 41 | mov di,12*160 + 36*2 42 | 43 | mov cx,9 ; length of the string 44 | s: mov al,[si] 45 | mov es:[di],al 46 | inc si 47 | add di,2 48 | loop s 49 | 50 | mov ax,4c00h 51 | int 21h 52 | do0end: nop 53 | 54 | code ends 55 | end start -------------------------------------------------------------------------------- /Lab10/lab10_1.asm: -------------------------------------------------------------------------------- 1 | ; Lab 10 2 | ; name: show_str 3 | ; func: display a string of text which ends with 0 at specified position with certain color 4 | ; args: (dh) = line(0~24), (dl) = column(0~79) 5 | ; (cl) = color, ds:si = where the string begins 6 | 7 | assume cs:code 8 | 9 | data segment 10 | db 'welcome to masm!',0 11 | data ends 12 | 13 | stack segment 14 | dd 0,0 15 | dd 0,0 16 | stack ends 17 | 18 | code segment 19 | start: mov dh,8 ; line 20 | mov dl,3 ; column 21 | mov cl,2 ; color (00000010b) 22 | mov ax,data 23 | mov ds,ax 24 | mov ax,stack 25 | mov ss,ax 26 | mov sp,20H 27 | 28 | mov si,0 29 | call show_str 30 | 31 | mov ax,4c00H 32 | int 21h 33 | 34 | show_str: push si 35 | push di 36 | push bx 37 | push bp 38 | push ax 39 | push dx 40 | push cx 41 | 42 | mov ax,0B800H 43 | mov es,ax 44 | 45 | mov al,0A0H 46 | mov bl,dh 47 | mul bl 48 | 49 | mov bp,ax ; first column of the line 50 | 51 | mov al,2 52 | mul dl 53 | add bp,ax ; exact position 54 | 55 | mov di,0 56 | mov dl,cl 57 | mov ch,0 58 | 59 | s: mov cl,ds:[si] 60 | jcxz done 61 | mov es:[bp+di],cl 62 | mov es:[bp+di+1],dl 63 | add di,2 64 | inc si 65 | jmp short s 66 | 67 | done: pop cx 68 | pop dx 69 | pop ax 70 | pop bp 71 | pop bx 72 | pop di 73 | pop si 74 | ret 75 | 76 | code ends 77 | 78 | end start -------------------------------------------------------------------------------- /Lab14/lab14.asm: -------------------------------------------------------------------------------- 1 | assume cs:code 2 | 3 | data segment 4 | db 'YY/MM/DD HH:MI:SS',0 ; 18 5 | db 9,8,7,4,2,0 6 | data ends 7 | 8 | stack segment 9 | dd 0,0 10 | stack ends 11 | 12 | code segment 13 | start: mov ax,data 14 | mov ds,ax 15 | mov ax,stack 16 | mov ss,ax 17 | mov sp,0 18 | mov si,0 19 | mov di,18 20 | mov cx,6 21 | s0: mov al,ds:[di] 22 | out 70h,al 23 | in al,71h 24 | 25 | mov ah,al 26 | mov cl,4 27 | shr ah,cl 28 | and al,00001111b 29 | 30 | mov bx,ax 31 | mov al,bh 32 | mov ah,bl 33 | 34 | add ax,3030h 35 | mov ds:[si],ax 36 | 37 | add si,3 38 | add di,1 39 | loop s0 40 | 41 | mov dh,12 ; line 42 | mov dl,30 ; column 43 | mov cl,0fh ; color 44 | mov si,0 45 | call show_str 46 | 47 | mov ax,4c00h 48 | int 21h 49 | 50 | show_str: push si 51 | push di 52 | push bx 53 | push bp 54 | push ax 55 | push dx 56 | push cx 57 | 58 | mov ax,0B800H 59 | mov es,ax 60 | 61 | mov al,0A0H 62 | mov bl,dh 63 | mul bl 64 | 65 | mov bp,ax ; first column of the line 66 | 67 | mov al,2 68 | mul dl 69 | add bp,ax ; exact position 70 | 71 | mov di,0 72 | mov dl,cl 73 | mov ch,0 74 | 75 | s: mov cl,ds:[si] 76 | jcxz done 77 | mov es:[bp+di],cl 78 | mov es:[bp+di+1],dl 79 | add di,2 80 | inc si 81 | jmp short s 82 | 83 | done: pop cx 84 | pop dx 85 | pop ax 86 | pop bp 87 | pop bx 88 | pop di 89 | pop si 90 | ret 91 | code ends 92 | end start -------------------------------------------------------------------------------- /Lab8/lab8.asm: -------------------------------------------------------------------------------- 1 | ; Requirements: 2 | ; Analyse the following program. Consider before running it: Will it returning normally? 3 | ; Think after running the program: why? 4 | 5 | ; before execution: 6 | ; 0B28:0000 B8004C MOV AX,4C00 7 | ; 0B28:0003 CD21 INT 21 8 | ; 0B28:0005 B80000 MOV AX,0000 <== start: 9 | ; 0B28:0008 90 NOP <== s: <-- `EBF6` will be placed here 10 | ; >> AFTER EXECUTION: 0B28:0008 EBF6 JMP 0000 hence the program will return normally 11 | ; 0B28:0009 90 NOP 12 | ; 0B28:000A BF0800 MOV DI,0008 13 | ; 0B28:000D BE2000 MOV SI,0020 14 | ; 0B28:0010 2E CS: 15 | ; 0B28:0011 8B04 MOV AX,[SI] 16 | ; 0B28:0013 2E CS: 17 | ; 0B28:0014 8905 MOV [DI],AX 18 | ; 0B28:0016 EBF0 JMP 0008 <== s0: 19 | ; 0B28:0018 B80000 MOV AX,0000 <== s1: 20 | ; 0B28:001B CD21 INT 21 21 | ; 0B28:001D B80000 MOV AX,0000 22 | ; 0B28:0020 EBF6 JMP 0018 <== s2: <-- HERE'S WHAT'S COPIED 23 | ; 0B28:0022 90 NOP 24 | ; 0B28:0023 2DFE06 SUB AX,06FE 25 | 26 | 27 | assume cs:codesg 28 | codesg segment 29 | 30 | mov ax,4c00h 31 | int 21h 32 | 33 | start: mov ax,0 34 | s: nop 35 | nop 36 | 37 | mov di,offset s 38 | mov si,offset s2 39 | mov ax,cs:[si] 40 | mov cs:[di],ax 41 | 42 | s0: jmp short s 43 | 44 | s1: mov ax,0 45 | int 21h 46 | mov ax,0 47 | 48 | s2: jmp short s1 49 | nop 50 | 51 | codesg ends 52 | end start 53 | -------------------------------------------------------------------------------- /Lab10/lab10_2.asm: -------------------------------------------------------------------------------- 1 | ; Lab 10 2 | ; name: divdw 3 | ; func: Do division that will not overflow. 4 | ; args: (ax) = dword, lower part of dividend 5 | ; (dx) = dword, higher part of dividend 6 | ; (cx) = divisor 7 | ; ret: (ax) = lower part of the quotient 8 | ; (dx) = higher part of the quotient 9 | ; (cx) = remainder 10 | 11 | assume cs:code 12 | 13 | data segment 14 | dd 0,0,0,0 15 | dd 0,0,0,0 16 | data ends 17 | 18 | stack segment 19 | dd 0,0 20 | stack ends 21 | 22 | code segment 23 | start: mov ax,data 24 | mov ds,ax 25 | 26 | mov ax,stack 27 | mov ss,ax 28 | mov sp,10H 29 | 30 | mov ax,4241H ; sample data begins 31 | mov dx,000FH ; >> Different from what is given in the textbook, the lower part of the dividend is 4241H instead of 4240H 32 | mov cx,0AH ; sample data ends 33 | 34 | call divdw 35 | 36 | mov ax,4c00H 37 | int 21h 38 | 39 | divdw: push bx 40 | 41 | mov bx,0 42 | push [bx+0] 43 | push [bx+2] 44 | push [bx+4] 45 | push [bx+6] 46 | push [bx+8] 47 | push [bx+10] 48 | 49 | mov [bx+0],ax ; dividend (lower) 50 | mov [bx+2],dx ; dividend (higher) 51 | mov [bx+4],cx ; divisor 52 | 53 | mov dx,0 54 | mov ax,[bx+2] 55 | div cx 56 | mov [bx+6],dx ; remainder of lhs H/N 57 | 58 | add ax,ax 59 | mov cx,8000H 60 | mul cx 61 | mov [bx+8],ax ; lower part of the lhs result 62 | mov [bx+10],dx ; higher part of the lhs result 63 | 64 | mov ax,[bx+6] 65 | add ax,ax 66 | mov cx,8000H 67 | mul cx 68 | add ax,[bx+0] 69 | div word ptr [bx+4] 70 | 71 | mov [bx+6],dx ; remainder 72 | add [bx+8],ax 73 | mov ax,[bx+8] 74 | mov dx,[bx+10] 75 | mov cx,[bx+6] 76 | 77 | mov bx,0 78 | pop [bx+10] 79 | pop [bx+8] 80 | pop [bx+6] 81 | pop [bx+4] 82 | pop [bx+2] 83 | pop [bx+0] 84 | pop bx 85 | ret 86 | 87 | code ends 88 | 89 | end start -------------------------------------------------------------------------------- /Lab13/lab13_2.asm: -------------------------------------------------------------------------------- 1 | ; Lab 13.2 - Interrupt Handler 2 | ; func: Loop 3 | ; args: (cx) = cycles; (bx) = offset 4 | 5 | ; ## NOTES 6 | ; 7 | ; * `int 7ch` context 8 | ; 9 | ; AX=B800 BX=FFF7 CX=0050 DX=0000 SP=0000 BP=0000 SI=0052 DI=0782 10 | ; DS=0B28 ES=B800 SS=0B28 CS=0B28 IP=003D NV UP EI PL NZ NA PE NC 11 | ; 0B28:003D CD7C INT 7C 12 | ; -t 13 | ; 14 | ; AX=B800 BX=FFF7 CX=0050 DX=0000 SP=FFFA BP=0000 SI=0052 DI=0782 15 | ; DS=0B28 ES=B800 SS=0B28 CS=0000 IP=0200 NV UP DI PL NZ NA PE NC 16 | ; 0000:0200 83E901 SUB CX,+01 17 | ; 18 | ; 19 | ; 20 | ; * `iret` context in the loop 21 | ; AX=B800 BX=FFF7 CX=004F DX=0000 SP=FFFA BP=0000 SI=0052 DI=0782 22 | ; DS=0B28 ES=B800 SS=0B28 CS=0000 IP=020C NV UP DI PL NZ AC PE CY 23 | ; 0000:020C CF IRET 24 | ; -t 25 | ; 26 | ; AX=B800 BX=FFF7 CX=004F DX=0000 SP=0000 BP=0000 SI=0052 DI=0782 27 | ; DS=0B28 ES=B800 SS=0B28 CS=0B28 IP=0036 NV UP EI PL NZ NA PE NC 28 | ; 0B28:0036 26 ES: 29 | ; 0B28:0037 C60521 MOV BYTE PTR [DI],21 ES:0782=30 30 | ; 31 | ; 32 | ; 33 | ; * `iret` context at the end of the loop 34 | ; AX=B800 BX=FFF7 CX=0000 DX=0000 SP=FFFA BP=0000 SI=0052 DI=0782 35 | ; DS=0B28 ES=B800 SS=0B28 CS=0000 IP=020C NV UP DI PL ZR NA PE NC 36 | ; 0000:020C CF IRET 37 | ; -t 38 | ; 39 | ; AX=B800 BX=FFF7 CX=0000 DX=0000 SP=0000 BP=0000 SI=0052 DI=0782 40 | ; DS=0B28 ES=B800 SS=0B28 CS=0B28 IP=003F NV UP EI PL NZ NA PE NC 41 | ; 0B28:003F 90 NOP 42 | ; 43 | 44 | assume cs:code 45 | code segment 46 | start: ; Set Up the Interrupt Handler 47 | mov ax,cs 48 | mov ds,ax 49 | mov si,offset do0 50 | mov ax,0 51 | mov es,ax 52 | mov di,200h 53 | 54 | mov cx,offset do0end-offset do0 55 | cld 56 | rep movsb 57 | 58 | ; Set Interrupt Vector Table 59 | mov ax,0 60 | mov es,ax 61 | mov word ptr es:[7ch*4],200h ; offset 62 | mov word ptr es:[7ch*4+2],0 ; segment 63 | 64 | ; Test the Handler 65 | mov ax,0b800h 66 | mov es,ax 67 | mov di,160*12 68 | mov bx,offset s-offset se 69 | mov cx,80 70 | s: mov byte ptr es:[di],'!' 71 | add di,2 72 | int 7ch 73 | se: nop 74 | 75 | mov ax,4c00h 76 | int 21h 77 | 78 | 79 | ; Interrupt Handler Start 80 | do0: sub cx,1 81 | jcxz el 82 | push bp 83 | mov bp,sp 84 | add [bp+2],bx 85 | pop bp 86 | el: iret 87 | 88 | do0end: nop 89 | 90 | code ends 91 | end start -------------------------------------------------------------------------------- /Lab13/lab13_1.asm: -------------------------------------------------------------------------------- 1 | ; Lab 13.1 - Interrupt Handler 2 | ; func: Display a string of text ends with 0 3 | ; args: (dh) = line(0~24), (dl) = column(0~79) 4 | ; (cl) = color, ds:si = where the string begins 5 | 6 | ; ## NOTES 7 | ; 8 | ; * `int 7ch` context 9 | ; 10 | ; AX=0B28 BX=0000 CX=0002 DX=0A0A SP=0000 BP=0000 SI=0000 DI=023F 11 | ; DS=0B28 ES=0000 SS=0B28 CS=0B2A IP=0036 NV UP EI PL NZ NA PO NC 12 | ; 0B2A:0036 CD7C INT 7C 13 | ; -t 14 | ; 15 | ; AX=0B28 BX=0000 CX=0002 DX=0A0A SP=FFFA BP=0000 SI=0000 DI=023F 16 | ; DS=0B28 ES=0000 SS=0B28 CS=0000 IP=0200 NV UP DI PL NZ NA PO NC 17 | ; 0000:0200 56 PUSH SI 18 | ; 19 | ; 20 | ; 21 | ; * `iret` context 22 | ; AX=0B28 BX=0000 CX=0002 DX=0A0A SP=FFFA BP=0000 SI=0000 DI=023F 23 | ; DS=0B28 ES=B800 SS=0B28 CS=0000 IP=0239 NV UP DI PL NZ NA PE NC 24 | ; 0000:0239 CF IRET 25 | ; -t 26 | ; 27 | ; AX=0B28 BX=0000 CX=0002 DX=0A0A SP=0000 BP=0000 SI=0000 DI=023F 28 | ; DS=0B28 ES=B800 SS=0B28 CS=0B2A IP=0038 NV UP EI PL NZ NA PO NC 29 | ; 0B2A:0038 B8004C MOV AX,4C00 30 | ; 31 | 32 | assume cs:code 33 | data segment 34 | db "welcome to masm! ",0 35 | data ends 36 | code segment 37 | start: ; Set Up the Interrupt Handler 38 | mov ax,cs 39 | mov ds,ax 40 | mov si,offset do0 41 | mov ax,0 42 | mov es,ax 43 | mov di,200h 44 | 45 | mov cx,offset do0end-offset do0 46 | cld 47 | rep movsb 48 | 49 | ; Set Interrupt Vector Table 50 | mov ax,0 51 | mov es,ax 52 | mov word ptr es:[7ch*4],200h ; offset 53 | mov word ptr es:[7ch*4+2],0 ; segment 54 | 55 | ; Test the Handler 56 | mov dh,10 57 | mov dl,10 58 | mov cl,2 59 | mov ax,data 60 | mov ds,ax 61 | mov si,0 62 | int 7ch 63 | 64 | mov ax,4c00h 65 | int 21h 66 | 67 | 68 | ; Interrupt Handler Start 69 | do0: push si 70 | push di 71 | push bx 72 | push bp 73 | push ax 74 | push dx 75 | push cx 76 | 77 | mov ax,0B800H 78 | mov es,ax 79 | 80 | mov al,0A0H 81 | mov bl,dh 82 | mul bl 83 | 84 | mov bp,ax ; first column of the line 85 | 86 | mov al,2 87 | mul dl 88 | add bp,ax ; exact position 89 | 90 | mov di,0 91 | mov dl,cl 92 | mov ch,0 93 | 94 | s: mov cl,ds:[si] 95 | jcxz done 96 | mov es:[bp+di],cl 97 | mov es:[bp+di+1],dl 98 | add di,2 99 | inc si 100 | jmp short s 101 | 102 | done: pop cx 103 | pop dx 104 | pop ax 105 | pop bp 106 | pop bx 107 | pop di 108 | pop si 109 | iret 110 | 111 | do0end: nop 112 | 113 | code ends 114 | end start -------------------------------------------------------------------------------- /Lab10/lab10_3.asm: -------------------------------------------------------------------------------- 1 | ; Lab 10 2 | ; name: wdtoc 3 | ; func: convert HEX word(8bit) data into a string of DEC which ends with 0 4 | ; args: (ax) = data (word) 5 | ; ds:si = where the string begins 6 | 7 | assume cs:code 8 | 9 | data segment 10 | db 10 dup (0) 11 | data ends 12 | 13 | stack segment 14 | dd 0,0 15 | dd 0,0 16 | stack ends 17 | 18 | code segment 19 | start: mov ax,data 20 | mov ds,ax 21 | mov ax,stack 22 | mov ss,ax 23 | mov sp,20H 24 | mov si,0 25 | 26 | mov ax,3 27 | call wdtoc 28 | 29 | mov dh,8 30 | mov dl,3 31 | mov cl,2 32 | call show_str 33 | 34 | mov ax,4c00H 35 | int 21h 36 | 37 | wdtoc: push ax 38 | push bx 39 | push cx 40 | push dx 41 | push si 42 | push di 43 | 44 | mov bx,0 45 | mov si,0 46 | 47 | wdtoc_s:mov dx,0 48 | mov cx,10 49 | call divdw 50 | add cl,30H ; DEC to ASCII 51 | mov ds:[bx+si],cl ; remainder (ASCII) 52 | mov cx,ax ; quotient 53 | inc si 54 | jcxz wdtoc_done 55 | jmp short wdtoc_s 56 | 57 | ; reverse the output 58 | wdtoc_done:push si 59 | sub si,1 60 | mov cx,si 61 | jcxz wdtoc_ret 62 | inc si 63 | mov ax,si 64 | mov cl,2 65 | div cl 66 | mov ch,0 67 | mov cl,al ; quotient = number of step for swapping 68 | mov di,si 69 | sub di,1 ; position of the last char 70 | mov si,0 ; position of the first char 71 | wdtoc_s1:mov al,ds:[bx+si] 72 | mov ah,ds:[bx+di] 73 | mov ds:[bx+si],ah 74 | mov ds:[bx+di],al 75 | sub di,1 76 | inc si 77 | loop wdtoc_s1 78 | 79 | wdtoc_ret: pop si 80 | mov al,0 81 | mov ds:[bx+si],al 82 | 83 | pop di 84 | pop si 85 | pop dx 86 | pop cx 87 | pop bx 88 | pop ax 89 | ret 90 | 91 | show_str: push si 92 | push di 93 | push bx 94 | push bp 95 | push ax 96 | push dx 97 | push cx 98 | 99 | mov ax,0B800H 100 | mov es,ax 101 | 102 | mov al,0A0H 103 | mov bl,dh 104 | mul bl 105 | 106 | mov bp,ax ; first column of the line 107 | 108 | mov al,2 109 | mul dl 110 | add bp,ax ; exact position 111 | 112 | mov di,0 113 | mov dl,cl 114 | mov ch,0 115 | 116 | str_s: mov cl,ds:[si] 117 | jcxz done 118 | mov es:[bp+di],cl 119 | mov es:[bp+di+1],dl 120 | add di,2 121 | inc si 122 | jmp short str_s 123 | 124 | done: pop cx 125 | pop dx 126 | pop ax 127 | pop bp 128 | pop bx 129 | pop di 130 | pop si 131 | ret 132 | 133 | divdw: push bx 134 | 135 | mov bx,0 136 | push [bx+0] 137 | push [bx+2] 138 | push [bx+4] 139 | push [bx+6] 140 | push [bx+8] 141 | push [bx+10] 142 | 143 | mov [bx+0],ax ; dividend (lower) 144 | mov [bx+2],dx ; dividend (higher) 145 | mov [bx+4],cx ; divisor 146 | 147 | mov dx,0 148 | mov ax,[bx+2] 149 | div cx 150 | mov [bx+6],dx ; remainder of lhs H/N 151 | 152 | add ax,ax 153 | mov cx,8000H 154 | mul cx 155 | mov [bx+8],ax ; lower part of the lhs result 156 | mov [bx+10],dx ; higher part of the lhs result 157 | 158 | mov ax,[bx+6] 159 | add ax,ax 160 | mov cx,8000H 161 | mul cx 162 | add ax,[bx+0] 163 | div word ptr [bx+4] 164 | 165 | mov [bx+6],dx ; remainder 166 | add [bx+8],ax 167 | mov ax,[bx+8] 168 | mov dx,[bx+10] 169 | mov cx,[bx+6] 170 | 171 | mov bx,0 172 | pop [bx+10] 173 | pop [bx+8] 174 | pop [bx+6] 175 | pop [bx+4] 176 | pop [bx+2] 177 | pop [bx+0] 178 | pop bx 179 | ret 180 | 181 | code ends 182 | 183 | end start -------------------------------------------------------------------------------- /Lab10/lab10_3r.asm: -------------------------------------------------------------------------------- 1 | ; Task in Project1 2 | ; @ Improved dtoc function, supporting the conversion from dword HEX into string 3 | ; 4 | ; name: dtoc 5 | ; func: convert HEX dword(16bit) data into a string of DEC which ends with 0 6 | ; args: (ax) = lower 16bit 7 | ; (dx) = higher 16bit 8 | ; ds:si = where the string begins 9 | 10 | assume cs:code 11 | 12 | data segment 13 | db 10 dup (0) 14 | data ends 15 | 16 | stack segment 17 | dd 0,0 18 | dd 0,0 19 | stack ends 20 | 21 | code segment 22 | start: mov ax,data 23 | mov ds,ax 24 | mov ax,stack 25 | mov ss,ax 26 | mov sp,20H 27 | mov si,0 28 | 29 | mov ax,9768H ; sample data (l) 30 | mov dx,005AH ; sample data (h) 31 | call dtoc 32 | 33 | mov dh,8 34 | mov dl,3 35 | mov cl,2 36 | call show_str 37 | 38 | mov ax,4c00H 39 | int 21h 40 | 41 | dtoc: push ax 42 | push bx 43 | push cx 44 | push dx 45 | push si 46 | push di 47 | 48 | mov bx,0 49 | mov si,0 50 | 51 | dtoc_s: mov cx,10 52 | call divdw 53 | add cl,30H ; DEC to ASCII 54 | mov ds:[bx+si],cl ; remainder (ASCII) 55 | mov cx,ax ; quotient 56 | inc si 57 | jcxz dtoc_done 58 | jmp short dtoc_s 59 | 60 | ; reverse the output 61 | dtoc_done: push si 62 | sub si,1 63 | mov cx,si 64 | jcxz dtoc_ret 65 | inc si 66 | mov ax,si 67 | mov cl,2 68 | div cl 69 | mov ch,0 70 | mov cl,al ; quotient = number of step for swapping 71 | mov di,si 72 | sub di,1 ; position of the last char 73 | mov si,0 ; position of the first char 74 | dtoc_s1: mov al,ds:[bx+si] 75 | mov ah,ds:[bx+di] 76 | mov ds:[bx+si],ah 77 | mov ds:[bx+di],al 78 | sub di,1 79 | inc si 80 | loop dtoc_s1 81 | 82 | dtoc_ret: pop si 83 | mov ax,0 84 | mov ds:[bx+si],ax 85 | 86 | pop di 87 | pop si 88 | pop dx 89 | pop cx 90 | pop bx 91 | pop ax 92 | ret 93 | 94 | show_str: push si 95 | push di 96 | push bx 97 | push bp 98 | push ax 99 | push dx 100 | push cx 101 | 102 | mov ax,0B800H 103 | mov es,ax 104 | 105 | mov al,0A0H 106 | mov bl,dh 107 | mul bl 108 | 109 | mov bp,ax ; first column of the line 110 | 111 | mov al,2 112 | mul dl 113 | add bp,ax ; exact position 114 | 115 | mov di,0 116 | mov dl,cl 117 | mov ch,0 118 | 119 | str_s: mov cl,ds:[si] 120 | jcxz done 121 | mov es:[bp+di],cl 122 | mov es:[bp+di+1],dl 123 | add di,2 124 | inc si 125 | jmp short str_s 126 | 127 | done: pop cx 128 | pop dx 129 | pop ax 130 | pop bp 131 | pop bx 132 | pop di 133 | pop si 134 | ret 135 | 136 | divdw: push bx 137 | 138 | mov bx,0 139 | push [bx+0] 140 | push [bx+2] 141 | push [bx+4] 142 | push [bx+6] 143 | push [bx+8] 144 | push [bx+10] 145 | 146 | mov [bx+0],ax ; dividend (lower) 147 | mov [bx+2],dx ; dividend (higher) 148 | mov [bx+4],cx ; divisor 149 | 150 | mov dx,0 151 | mov ax,[bx+2] 152 | div cx 153 | mov [bx+6],dx ; remainder of lhs H/N 154 | 155 | add ax,ax 156 | mov cx,8000H 157 | mul cx 158 | mov [bx+8],ax ; lower part of the lhs result 159 | mov [bx+10],dx ; higher part of the lhs result 160 | 161 | mov ax,[bx+6] 162 | add ax,ax 163 | mov cx,8000H 164 | mul cx 165 | add ax,[bx+0] 166 | div word ptr [bx+4] 167 | 168 | mov [bx+6],dx ; remainder 169 | add [bx+8],ax 170 | mov ax,[bx+8] 171 | mov dx,[bx+10] 172 | mov cx,[bx+6] 173 | 174 | mov bx,0 175 | pop [bx+10] 176 | pop [bx+8] 177 | pop [bx+6] 178 | pop [bx+4] 179 | pop [bx+2] 180 | pop [bx+0] 181 | pop bx 182 | ret 183 | 184 | code ends 185 | 186 | end start -------------------------------------------------------------------------------- /Lab7/lab7.asm: -------------------------------------------------------------------------------- 1 | assume cs:codesg 2 | 3 | data segment 4 | db '1975','1976','1977','1978','1979','1980','1981','1982','1983' 5 | db '1984','1985','1986','1987','1988','1989','1990','1991','1992' 6 | db '1993','1994','1995' 7 | ; 21 strings that represent 21 years 8 | 9 | dd 16,22,382,1356,2390,8000,16000,24486,50065,97479,140417,197514 10 | dd 345980,590827,803530,1183000,1843000,2759000,3753000,4649000,5937000 11 | ; 21 dword data that represents total income of Power Idea for 21 years 12 | 13 | dw 3,7,9,13,28,38,130,220,476,778,1001,1442,2258,2793,4037,5635,8226 14 | dw 11542,14430,15257,17800 15 | ; numbers of employees for 21 years 16 | 17 | ;-d0B28:0 ff 18 | ;0B28:0000 31 39 37 35 31 39 37 36-31 39 37 37 31 39 37 38 1975197619771978 19 | ;0B28:0010 31 39 37 39 31 39 38 30-31 39 38 31 31 39 38 32 1979198019811982 20 | ;0B28:0020 31 39 38 33 31 39 38 34-31 39 38 35 31 39 38 36 1983198419851986 21 | ;0B28:0030 31 39 38 37 31 39 38 38-31 39 38 39 31 39 39 30 1987198819891990 22 | ;0B28:0040 31 39 39 31 31 39 39 32-31 39 39 33 31 39 39 34 1991199219931994 23 | ;0B28:0050 31 39 39 35 10 00 00 00-16 00 00 00 7E 01 00 00 1995........~... 24 | ;0B28:0060 4C 05 00 00 56 09 00 00-40 1F 00 00 80 3E 00 00 L...V...@....>.. 25 | ;0B28:0070 A6 5F 00 00 91 C3 00 00-C7 7C 01 00 81 24 02 00 ._.......|...$.. 26 | ;0B28:0080 8A 03 03 00 7C 47 05 00-EB 03 09 00 CA 42 0C 00 ....|G.......B.. 27 | ;0B28:0090 18 0D 12 00 38 1F 1C 00-58 19 2A 00 28 44 39 00 ....8...X.*.(D9. 28 | ;0B28:00A0 28 F0 46 00 68 97 5A 00-03 00 07 00 09 00 0D 00 (.F.h.Z......... 29 | ;0B28:00B0 1C 00 26 00 82 00 DC 00-DC 01 0A 03 E9 03 A2 05 ..&............. 30 | ;0B28:00C0 D2 08 E9 0A C5 0F 03 16-22 20 16 2D 5E 38 99 3B ........" .-^8.; 31 | ;0B28:00D0 88 45 00 00 00 00 00 00-00 00 00 00 00 00 00 00 .E.............. 32 | ;0B28:00E0 79 65 61 72 20 73 75 6D-6D 20 6E 65 20 3F 3F 20 year summ ne ?? 33 | ;0B28:00F0 79 65 61 72 20 73 75 6D-6D 20 6E 65 20 3F 3F 20 year summ ne ?? 34 | data ends 35 | 36 | table segment 37 | db 21 dup ('year summ ne ?? ') 38 | table ends 39 | 40 | stack segment 41 | db 16 dup (0) 42 | stack ends 43 | 44 | codesg segment 45 | start: mov ax,data 46 | mov ds,ax 47 | mov ax,stack ; stack start 48 | mov ss,ax 49 | mov bp,00E0H ; table start 50 | 51 | mov bx,0 52 | mov si,0 53 | mov cx,21 54 | 55 | ; year 56 | s: push cx 57 | mov cx,2 58 | mov di,0 59 | s_year: mov ax,[bx+si] 60 | mov ds:[bp+di],ax 61 | add si,2 62 | add di,2 63 | loop s_year 64 | add bp,16 65 | pop cx 66 | loop s 67 | 68 | ; profit 69 | mov si,0 70 | mov bx,0054H 71 | mov bp,00E5H 72 | mov cx,21 73 | s1: push cx 74 | mov di,0 75 | mov cx,2 76 | s_sum: mov ax,[bx+si] 77 | mov ds:[bp+di],ax 78 | add si,2 79 | add di,2 80 | loop s_sum 81 | add bp,16 82 | pop cx 83 | loop s1 84 | 85 | ; number of employees 86 | mov si,0 87 | mov bx,00A8H 88 | mov bp,00EAH 89 | mov cx,21 90 | s2: mov ax,[bx+si] 91 | mov ds:[bp],ax 92 | add si,2 93 | add bp,16 94 | loop s2 95 | 96 | ; average profit per employee 97 | mov bx,00E5H ; summ 98 | mov bp,00EAH ; ne 99 | mov si,0 100 | mov cx,21 101 | s3: mov ax,[bx+si] 102 | mov dx,[bx+si+2] 103 | div word ptr ds:[bp+si] 104 | mov [bx+si+8],ax 105 | add si,16 106 | loop s3 107 | 108 | mov ax,4c00H 109 | int 21H 110 | codesg ends 111 | 112 | end start 113 | 114 | ; ===== Result ===== 115 | ;0B28:00E0 31 39 37 35 20 10 00 00-00 20 03 00 20 05 00 20 1975 .... .. .. 116 | ;0B28:00F0 31 39 37 36 20 16 00 00-00 20 07 00 20 03 00 20 1976 .... .. .. 117 | ;0B28:0100 31 39 37 37 20 7E 01 00-00 20 09 00 20 2A 00 20 1977 ~... .. *. 118 | ;0B28:0110 31 39 37 38 20 4C 05 00-00 20 0D 00 20 68 00 20 1978 L... .. h. 119 | ;0B28:0120 31 39 37 39 20 56 09 00-00 20 1C 00 20 55 00 20 1979 V... .. U. 120 | ;0B28:0130 31 39 38 30 20 40 1F 00-00 20 26 00 20 D2 00 20 1980 @... &. .. 121 | ;0B28:0140 31 39 38 31 20 80 3E 00-00 20 82 00 20 7B 00 20 1981 .>.. .. {. 122 | ;0B28:0150 31 39 38 32 20 A6 5F 00-00 20 DC 00 20 6F 00 20 1982 ._.. .. o. 123 | ;0B28:0160 31 39 38 33 20 91 C3 00-00 20 DC 01 20 69 00 20 1983 .... .. i. 124 | ;0B28:0170 31 39 38 34 20 C7 7C 01-00 20 0A 03 20 7D 00 20 1984 .|.. .. }. 125 | ;0B28:0180 31 39 38 35 20 81 24 02-00 20 E9 03 20 8C 00 20 1985 .$.. .. .. 126 | ;0B28:0190 31 39 38 36 20 8A 03 03-00 20 A2 05 20 88 00 20 1986 .... .. .. 127 | ;0B28:01A0 31 39 38 37 20 7C 47 05-00 20 D2 08 20 99 00 20 1987 |G.. .. .. 128 | ;0B28:01B0 31 39 38 38 20 EB 03 09-00 20 E9 0A 20 D3 00 20 1988 .... .. .. 129 | ;0B28:01C0 31 39 38 39 20 CA 42 0C-00 20 C5 0F 20 C7 00 20 1989 .B.. .. .. 130 | ;0B28:01D0 31 39 39 30 20 18 0D 12-00 20 03 16 20 D1 00 20 1990 .... .. .. 131 | ;0B28:01E0 31 39 39 31 20 38 1F 1C-00 20 22 20 20 E0 00 20 1991 8... " .. 132 | ;0B28:01F0 31 39 39 32 20 58 19 2A-00 20 16 2D 20 EF 00 20 1992 X.*. .- .. 133 | ;0B28:0200 31 39 39 33 20 28 44 39-00 20 5E 38 20 04 01 20 1993 (D9. ^8 .. 134 | ;0B28:0210 31 39 39 34 20 28 F0 46-00 20 99 3B 20 30 01 20 1994 (.F. .; 0. 135 | ;0B28:0220 31 39 39 35 20 68 97 5A-00 20 88 45 20 4D 01 20 1995 h.Z. .E M. -------------------------------------------------------------------------------- /Project1/proj1.asm: -------------------------------------------------------------------------------- 1 | assume cs:codesg 2 | 3 | data segment 4 | db '1975','1976','1977','1978','1979','1980','1981','1982','1983' 5 | db '1984','1985','1986','1987','1988','1989','1990','1991','1992' 6 | db '1993','1994','1995' 7 | ; 21 strings that represent 21 years 8 | 9 | dd 16,22,382,1356,2390,8000,16000,24486,50065,97479,140417,197514 10 | dd 345980,590827,803530,1183000,1843000,2759000,3753000,4649000,5937000 11 | ; 21 dword data that represents total income of Power Idea for 21 years 12 | 13 | dw 3,7,9,13,28,38,130,220,476,778,1001,1442,2258,2793,4037,5635,8226 14 | dw 11542,14430,15257,17800 15 | ; numbers of employees for 21 years 16 | data ends 17 | 18 | table segment 19 | db 21 dup ('year summ ne ?? ') 20 | table ends 21 | 22 | stack segment 23 | db 16 dup (0) 24 | stack ends 25 | 26 | codesg segment 27 | start: mov ax,data 28 | mov ds,ax 29 | mov ax,stack ; stack start 30 | mov ss,ax 31 | mov bp,00E0H ; table start 32 | 33 | mov bx,0 34 | mov si,0 35 | mov cx,21 36 | 37 | ; year 38 | s: push cx 39 | mov cx,2 40 | mov di,0 41 | s_year: mov ax,[bx+si] 42 | mov ds:[bp+di],ax 43 | add si,2 44 | add di,2 45 | loop s_year 46 | add bp,16 47 | pop cx 48 | loop s 49 | 50 | ; profit 51 | mov si,0 52 | mov bx,0054H 53 | mov bp,00E5H 54 | mov cx,21 55 | s1: push cx 56 | mov di,0 57 | mov cx,2 58 | s_sum: mov ax,[bx+si] 59 | mov ds:[bp+di],ax 60 | add si,2 61 | add di,2 62 | loop s_sum 63 | add bp,16 64 | pop cx 65 | loop s1 66 | 67 | ; number of employees 68 | mov si,0 69 | mov bx,00A8H 70 | mov bp,00EAH 71 | mov cx,21 72 | s2: mov ax,[bx+si] 73 | mov ds:[bp],ax 74 | add si,2 75 | add bp,16 76 | loop s2 77 | 78 | ; average profit per employee 79 | mov bx,00E5H ; summ 80 | mov bp,00EAH ; ne 81 | mov si,0 82 | mov cx,21 83 | s3: mov ax,[bx+si] 84 | mov dx,[bx+si+2] 85 | div word ptr ds:[bp+si] 86 | mov [bx+si+8],ax 87 | add si,16 88 | loop s3 89 | 90 | 91 | ; print data 92 | 93 | mov ax,data 94 | mov ds,ax 95 | mov bx,0 96 | mov di,0 97 | mov bp,00E0H ; table start 98 | 99 | mov dh,2 100 | 101 | mov cx,21 102 | ; print table rows 103 | print_tr: push cx 104 | mov cl,01110000B 105 | 106 | ; year 107 | mov ax,ds:[bp] 108 | mov [bx],ax 109 | mov ax,ds:[bp+2] 110 | mov [bx+2],ax 111 | mov ax,0 112 | mov [bx+4],ax 113 | mov si,0 114 | mov dl,0 115 | call show_str 116 | 117 | ; income 118 | push dx 119 | mov ax,ds:[bp+5] 120 | mov dx,ds:[bp+7] 121 | mov si,0 122 | call dtoc 123 | 124 | pop dx 125 | mov dl,10 126 | call show_str 127 | 128 | ; employees 129 | push dx 130 | mov ax,ds:[bp+10] 131 | mov dx,0 132 | mov si,0 133 | call dtoc 134 | 135 | pop dx 136 | mov dl,20 137 | call show_str 138 | 139 | ; avg profit per employee 140 | push dx 141 | mov ax,ds:[bp+0dH] 142 | mov dx,0 143 | mov si,0 144 | call dtoc 145 | 146 | pop dx 147 | mov dl,30 148 | call show_str 149 | 150 | inc dh 151 | add bp,10H 152 | pop cx 153 | loop print_tr 154 | 155 | mov ax,4c00H 156 | int 21H 157 | 158 | 159 | ; Utils 160 | dtoc: push ax 161 | push bx 162 | push cx 163 | push dx 164 | push si 165 | push di 166 | 167 | mov bx,0 168 | mov si,0 169 | 170 | dtoc_s: mov cx,10 171 | call divdw 172 | add cl,30H ; DEC to ASCII 173 | mov ds:[bx+si],cl ; remainder (ASCII) 174 | mov cx,ax ; quotient 175 | inc si 176 | jcxz dtoc_done 177 | jmp short dtoc_s 178 | 179 | dtoc_done: push si 180 | sub si,1 181 | mov cx,si 182 | jcxz dtoc_ret 183 | inc si 184 | mov ax,si 185 | mov cl,2 186 | div cl 187 | mov ch,0 188 | mov cl,al ; quotient = number of step for swapping 189 | mov di,si 190 | sub di,1 ; position of the last char 191 | mov si,0 ; position of the first char 192 | dtoc_s1: mov al,ds:[bx+si] 193 | mov ah,ds:[bx+di] 194 | mov ds:[bx+si],ah 195 | mov ds:[bx+di],al 196 | sub di,1 197 | inc si 198 | loop dtoc_s1 199 | 200 | dtoc_ret: pop si 201 | mov ax,0 202 | mov ds:[bx+si],ax 203 | 204 | pop di 205 | pop si 206 | pop dx 207 | pop cx 208 | pop bx 209 | pop ax 210 | ret 211 | 212 | show_str: push si 213 | push di 214 | push bx 215 | push bp 216 | push ax 217 | push dx 218 | push cx 219 | 220 | mov ax,0B800H 221 | mov es,ax 222 | 223 | mov al,0A0H 224 | mov bl,dh 225 | mul bl 226 | 227 | mov bp,ax ; first column of the line 228 | 229 | mov al,2 230 | mul dl 231 | add bp,ax ; exact position 232 | 233 | mov di,0 234 | mov dl,cl 235 | mov ch,0 236 | 237 | str_s: mov cl,ds:[si] 238 | jcxz done 239 | mov es:[bp+di],cl 240 | mov es:[bp+di+1],dl 241 | add di,2 242 | inc si 243 | jmp short str_s 244 | 245 | done: pop cx 246 | pop dx 247 | pop ax 248 | pop bp 249 | pop bx 250 | pop di 251 | pop si 252 | ret 253 | 254 | divdw: push bx 255 | 256 | mov bx,0 257 | push [bx+0] 258 | push [bx+2] 259 | push [bx+4] 260 | push [bx+6] 261 | push [bx+8] 262 | push [bx+10] 263 | 264 | mov [bx+0],ax ; dividend (lower) 265 | mov [bx+2],dx ; dividend (higher) 266 | mov [bx+4],cx ; divisor 267 | 268 | mov dx,0 269 | mov ax,[bx+2] 270 | div cx 271 | mov [bx+6],dx ; remainder of lhs H/N 272 | 273 | add ax,ax 274 | mov cx,8000H 275 | mul cx 276 | mov [bx+8],ax ; lower part of the lhs result 277 | mov [bx+10],dx ; higher part of the lhs result 278 | 279 | mov ax,[bx+6] 280 | add ax,ax 281 | mov cx,8000H 282 | mul cx 283 | add ax,[bx+0] 284 | div word ptr [bx+4] 285 | 286 | mov [bx+6],dx ; remainder 287 | add [bx+8],ax 288 | mov ax,[bx+8] 289 | mov dx,[bx+10] 290 | mov cx,[bx+6] 291 | 292 | mov bx,0 293 | pop [bx+10] 294 | pop [bx+8] 295 | pop [bx+6] 296 | pop [bx+4] 297 | pop [bx+2] 298 | pop [bx+0] 299 | pop bx 300 | ret 301 | 302 | codesg ends 303 | 304 | end start --------------------------------------------------------------------------------