Exp No: 02 Aim: Objectives:: Number - of - Params Macro - Name
Exp No: 02 Aim: Objectives:: Number - of - Params Macro - Name
AIM: Write an X86/64 ALP to accept a string and to display its length.
OBJECTIVES:
ENVIRONMENT:
THEORY:
MACRO:
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.
ALGORITHM:
INPUT: String
STEP 1: Start.
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.
13
STEP 13: else add 30h into al
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.
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
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:
ENVIRONMENT:
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