Docsity

Assembly language lab manual, Summaries of Assembly Language Programming

Toggle sidebar
bg1
Assembly Language  Lab Manual
1 Write a program to display a single character
includelib kernel32.lib
ex t e rn Ge t S t d H a n d l e :proc
ex t e rn W r i t e C o n s o l e A :proc
ex t e rn Ex i t P r o c e s s :proc
.data character db
'
A
'
ha n d le dq ?
wr i t t e n dq ?
.code
ma in proc
su b rs p , 28 h
mo v rc x , -1 1
ca ll GetStdH a n d l e
mo v ha ndl e , ra x
mo v rc x , ha nd le
le a rd x , ch ar ac t er
mov r8 , 1
lea r9 , wr i t t e n
mov qword ptr [ r sp +32], 0
call WriteConsoleA
xo r rc x , rc x
ca ll ExitProcess
ma in endp
end
2 Write a program to print "Hello World"
includelib kernel32.lib
ex t e rn Ge t S t d H a n d l e :proc
ex t e rn W r i t e C o n s o l e A :proc
ex t e rn Ex i t P r o c e s s :proc
.data msg db
'
He llo , Worl d
'
, 0
1
pf3
pf4
pf5

Partial preview of the text

Download Assembly language lab manual and more Summaries Assembly Language Programming in PDF only on Docsity!

Assembly Language  Lab Manual

1 Write a program to display a single character

includelib kernel32.lib extern GetStdHandle : proc extern WriteConsoleA : proc extern ExitProcess : proc

.data character db 'A ' handle dq? written dq?

.code main proc sub rsp , 28 h mov rcx , - call GetStdHandle mov handle , rax mov rcx , handle lea rdx , character mov r8 , 1 lea r9 , written mov qword ptr [ rsp +32] , 0 call WriteConsoleA xor rcx , rcx call ExitProcess main endp end

2 Write a program to print "Hello World"

includelib kernel32.lib extern GetStdHandle : proc extern WriteConsoleA : proc extern ExitProcess : proc

.data msg db ' Hello , World ' , 0

handle dq? written dq?

.code main proc sub rsp , 28 h mov rcx , - call GetStdHandle mov handle , rax mov rcx , handle lea rdx , msg mov r8 , lengthof msg lea r9 , written mov qword ptr [ rsp +32] , 0 call WriteConsoleA xor rcx , rcx call ExitProcess main endp end

3 Write a program to display name and insti-

tution with newline

includelib kernel32.lib extern GetStdHandle : proc extern WriteConsoleA : proc extern ExitProcess : proc

.data msg1 db ' Muhammad Nadeem ' , 13 , 10 msg1Len equ $ - msg msg2 db ' Government Associate College Sinawan ' , 13 , msg2Len equ $ - msg handle dq? written dq?

.code main proc sub rsp , 28 h mov rcx , -

sub rsp , 28 h call GetStdHandle mov handle , rax

mov al , digit add al , ' 0 ' ; convert to ASCII ( ' 5 ') mov digit , al

mov rcx , handle lea rdx , digit mov r8 , 1 lea r9 , written call WriteConsoleA

xor rcx , rcx ; exit code = 0 call ExitProcess

main endp end

5 Write a program to take input from the user

with echo

includelib kernel32.lib

extern GetStdHandle : proc extern ReadConsoleA : proc extern WriteConsoleA : proc extern ExitProcess : proc

.data buffer db 100 dup (0) bytesRead dd? bytesWritten dd? hIn dq? ; Input handle hOut dq? ; Output handle

.code main proc sub rsp , 28 h

mov rcx , - call GetStdHandle mov hIn , rax

mov rcx , - call GetStdHandle mov hOut , rax

; Read input from the user mov rcx , hIn lea rdx , buffer mov r8d , 100 lea r9 , bytesRead mov qword ptr [ rsp +20 h ] , 0 call ReadConsoleA

; Print user input mov rcx , hOut lea rdx , buffer mov eax , bytesRead mov r8d , eax lea r9 , bytesWritten mov qword ptr [ rsp +20 h ] , 0 call WriteConsoleA

xor rcx , rcx call ExitProcess main endp end

6 Write a program to take input from user with-

out echo

includelib kernel32.lib

extern GetStdHandle : proc extern ReadConsoleA : proc extern WriteConsoleA : proc extern GetConsoleMode : proc extern SetConsoleMode : proc extern ExitProcess : proc

lea rdx , buffer mov r8d , 100 lea r9 , bytesRead mov qword ptr [ rsp +20 h ] , 0 call ReadConsoleA

; Reset console mode to echo mov rcx , hIn mov edx , oldMode call SetConsoleMode

; Print user input mov rcx , hOut lea rdx , buffer mov eax , bytesRead mov r8d , eax lea r9 , bytesWritten mov qword ptr [ rsp +20 h ] , 0 call WriteConsoleA

xor rcx , rcx call ExitProcess main endp end