Computer Organization and Assembly Language (COAL) Lab 10: Ali Naqi (23F-3052)
Computer Organization and Assembly Language (COAL) Lab 10: Ali Naqi (23F-3052)
Lab 10
Ali Naqi (23F-3052)
Question 1:
Code:
[org 0x0100]
jmp start
message : db 'hello world', 0
clrscr :
push ax
push di
push es
mov di, 0
mov ax, 0xb800
mov es, ax
mov ax, 0x720
mov cx, 2000
cld
rep stosw
pop es
pop di
pop ax
ret
strlen : push bp
mov bp, sp
push es
push ax
push cx
push si
push di
push ds
pop es
les di, [bp + 4]
mov cx, 0xffff
xor al, al
repne scasb
mov ax, 0xffff
sub ax, cx
dec ax
pop di
pop si
pop cx
pop ax
pop es
pop bp
ret 8
start:
; call clrscr
mov ax, message
push ax
call strlen
mov ax, 0x4c00
int 0x21
Output:
Question 2:
Code:
[org 0x0100]
jmp start
message : db 'hello world', 0
clrscr :
push ax
push di
push es
mov di, 0
mov ax, 0xb800
mov es, ax
mov ax, 0x720
mov cx, 2000
cld
rep stosw
pop es
pop di
pop ax
ret
printstr : push bp
mov bp, sp
push es
push ax
push cx
push si
push di
push ds
pop es
mov di, [bp + 4]
mov cx, 0xffff
xor al, al
repne scasb
mov ax, 0xffff
sub ax, cx
dec ax
jz exit
mov cx, ax
mov ax, 0xb800
mov es, ax
mov al, 80
mul byte[bp + 8]
add ax, [bp + 10]
shl ax, 1
mov di, ax
mov si, [bp + 4]
mov ah, [bp + 6]
cld
nextchar : lodsb
stosw
loop nextchar
exit : pop di
pop si
pop cx
pop ax
pop es
pop bp
ret 8
start:
call clrscr
mov ax, 20
push ax
mov ax, 10
push ax
mov ax, 0x07
push ax
mov ax, message
push ax
call printstr
mov ax, 0x4c00
int 0x21
Output:
Question 3:
Code:
[org 0x0100]
jmp start
message : db 'hello world', 0
clrscr :
push ax
push di
push es
mov di, 0
mov ax, 0xb800
mov es, ax
mov ax, 0x720
mov cx, 2000
cld
rep stosw
pop es
pop di
pop ax
ret
printstr : push bp
mov bp, sp
push es
push ax
push cx
push si
push di
push ds
pop es
mov di, [bp + 4]
mov cx, 0xffff
xor al, al
repne scasb
mov ax, 0xffff
sub ax, cx
dec ax
jz exit
mov cx, ax
mov ax, 0xb800
mov es, ax
mov al, 80
mul byte[bp + 8]
add ax, [bp + 10]
shl ax, 1
mov di, ax
mov si, [bp + 4]
mov ah, [bp + 6]
cld
nextchar : lodsb
stosw
loop nextchar
exit : pop di
pop si
pop cx
pop ax
pop es
pop bp
ret 8
start:
call clrscr
mov ax, 20
push ax
mov ax, 10
push ax
mov ax, 0x07
push ax
mov ax, message
push ax
call printstr
mov ax, 0x4c00
int 0x21
Output: