0% found this document useful (0 votes)
16 views5 pages

Exp No: 02 Aim: Objectives:: Number - of - Params Macro - Name

hufdhgfjdhgfdgfd gjfg

Uploaded by

patyogendra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views5 pages

Exp No: 02 Aim: Objectives:: Number - of - Params Macro - Name

hufdhgfjdhgfdgfd gjfg

Uploaded by

patyogendra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

EXP NO: 02

AIM: Write an X86/64 ALP to accept a string and to display its length.

OBJECTIVES:

 To understand assembly language programming instruction set.


 To understand different assembler directives with example.
 To apply instruction set for implementing X86/64 bit assembly language programs

ENVIRONMENT:

 Operating System: 64-bit Open source Linux or its derivative.


 Programming Tools: Preferably using Linux equivalent or MASM/TASM/NASM/FASM.
 Text Editor: geditor

THEORY:

MACRO:

Writing a macro is another way of ensuring modular programming in assembly language.


 A macro is a sequence of instructions, assigned by a name and could be used anywhere in the
program.
 In NASM, macros are defined with %macro and %endmacro directives.
 The macro begins with the %macro directive and ends with the %endmacro directive.
The Syntax for macro definition −
%macro macro_name number_of_params
<macro body>
%endmacro
Where, number_of_params specifies the number parameters, macro_name specifies the name of the
macro.
The macro is invoked by using the macro name along with the necessary parameters. When you need to
use some sequence of instructions many times in a program, you can put those instructions in a macro
and use it instead of writing the instructions all the time.
PROCEDURE:

Procedures or subroutines are very important in assembly language, as the assembly language programs
tend to be large in size. Procedures are identified by a name. Following this name, the body of the
procedure is described which performs a well-defined job. End of the procedure is indicated by a return
statement.

Syntax

12
Following is the syntax to define a procedure −
proc_name:
procedure body
...
ret
The procedure is called from another function by using the CALL instruction. The CALL instruction
should have the name of the called procedure as an argument as shown below −
CALL proc_name
The called procedure returns the control to the calling procedure by using the RET instruction.

LIST OF INTERRRUPTS USED: NA

LIST OF ASSEMBLER DIRECTIVES USED: EQU, PROC, GLOBAL, DB,

LIST OF MACROS USED: DISPMSG

LIST OF PROCEDURES USED: DISPLAY

ALGORITHM:

INPUT: String

OUTPUT: Length of String in hex

STEP 1: Start.

STEP 2: Initialize data section.

STEP 3: Display msg1 on monitor

STEP 4: accept string from user and store it in Rsi Register (Its length gets stored in Rax register by
default).

STEP 5: Display the result using “display” procedure. Load length of string in data register.

STEP 6. Take counter as 16 int cnt variable

STEP 7: move address of “result” variable into rdi.

STEP 8: Rotate left rbx register by 4 bit.

STEP 9: Move bl into al.

STEP 10: And al with 0fh

STEP 11: Compare al with 09h

STEP 12: If greater add 37h into al

13
STEP 13: else add 30h into al

STEP 14: Move al into memory location pointed by rdi

STEP 14: Increment rdi

STEP 15: Loop the statement till counter value becomes zero

STEP 16: Call macro dispmsg and pass result variable and length to it. It will print length of string.

STEP 17: Return from procedure

STEP 18: Stop

FLOWCHART:

PROGRAM:

section .data
msg1 db 10,13,"Enter a string:"
len1 equ $-msg1

section .bss
str1 resb 200 ;string declaration
result resb 16

section .text

global _start
_start:

;display
mov Rax,1
mov Rdi,1
mov Rsi,msg1
mov Rdx,len1
syscall

;store string

mov rax,0
mov rdi,0
mov rsi,str1
mov rdx,200
syscall

call display

;exit system call


mov Rax ,60
mov Rdi,0
syscall

14
%macro dispmsg 2
mov Rax,1
mov Rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endmacro

display:
mov rbx,rax ; store no in rbx
mov rdi,result ;point rdi to result variable
mov cx,16 ;load count of rotation in cl

up1:
rol rbx,04 ;rotate no of left by four bits
mov al,bl ; move lower byte in al
and al,0fh ;get only LSB
cmp al,09h ;compare with 39h
jg add_37 ;if greater than 39h skip add 37
add al,30h
jmp skip ;else add 30
add_37:
add al,37h
skip:
mov [rdi],al ;store ascii code in result variable
inc rdi ; point to next byte
dec cx ; decrement counter
jnz up1 ; if not zero jump to repeat
dispmsg result,16 ;call to macro
ret

OUTPUT:

CONCLUSION: In this practical session, we learnt how to display any number on monitor. (Convesion
of hex to ascii number in ALP program).

15
EXP NO: 03

AIM: Write an X86/64 ALP to find the largest of given Byte/Word/Dword/64-bit numbers

OBJECTIVES:

 To understand assembly language programming instruction set.


 To understand different assembler directives with example.
 To apply instruction set for implementing X86/64 bit assembly language programs

ENVIRONMENT:

 Operating System: 64-bit Open source Linux or its derivative.


 Programming Tools: Preferably using Linux equivalent or MASM/TASM/NASM/FASM.
 Text Editor: geditor

THEORY:

Datatype in 80386:

Datatypes of 80386:
The 80386 supports the following data types they are

 Bit
 Bit Field: A group of at the most 32 bits (4bytes)
 Bit String: A string of contiguous bits of maximum 4Gbytes in length.
 Signed Byte: Signed byte data
 Unsigned Byte: Unsigned byte data.
 Integer word: Signed 16-bit data.
 Long Integer: 32-bit signed data represented in 2's complement form.
 Unsigned Integer Word: Unsigned 16-bit data
 Unsigned Long Integer: Unsigned 32-bit data
 Signed Quad Word: A signed 64-bit data or four word data.
 Unsigned Quad Word: An unsigned 64-bit data.
 Offset: 16/32-bit displacement that points a memory location using any of the addressing modes.
 Pointer: This consists of a pair of 16-bit selector and 16/32-bit offset.
 Character: An ASCII equivalent to any of the alphanumeric or control characters.
 Strings: These are the sequences of bytes, words or double words. A string may contain minimum one byte and maximum 4
Gigabytes.
 BCD: Decimal digits from 0-9 represented by unpacked bytes.
 Packed BCD: This represents two packed BCD digits using a byte, i.e. from 00 to 99.

16

You might also like