0% found this document useful (0 votes)
24 views

LAB5 Implementation of String Instructions

This document describes a lab assignment on implementing string manipulation instructions in assembly language using the Irvine64 library. The objectives are to link Irvine64 with Visual Studio code, learn the string functions in Irvine64 like Str_compare, Str_copy and Str_length, and implement strings. The document then lists the functions provided by the Irvine64 library for string and console input/output. It provides sample code showing usage of various string functions like writing strings, comparing strings, finding string length, and copying strings.

Uploaded by

alihassan009669
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

LAB5 Implementation of String Instructions

This document describes a lab assignment on implementing string manipulation instructions in assembly language using the Irvine64 library. The objectives are to link Irvine64 with Visual Studio code, learn the string functions in Irvine64 like Str_compare, Str_copy and Str_length, and implement strings. The document then lists the functions provided by the Irvine64 library for string and console input/output. It provides sample code showing usage of various string functions like writing strings, comparing strings, finding string length, and copying strings.

Uploaded by

alihassan009669
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

(CS-222) Computer Organization and Assembly Language

Course Instructor: Kainat Ibrar


Lab Instructor: Kainat Ibrar

Lab 5- Implementation of String Manipulation Instructions

Objective
 Linking Irvine64 with the Visual Studio code
s
 Learning available strings’ functions in Irvine64
o Basic Syntax, Semantics and default registers
o Str_compare, Str_copy, Strjlength
 Implementation of strings using Irvine64 library functions

Assembly language Irvine64 link library


In this lab we will learn about a minimal link library that can support 64-bit programming, which
includes the following procedures:
 Crlf: Write a line ending sequence to the console.
 Random64: Generate a 64-bit pseudo-random integer within 0~2⁶⁴-1. The random
value is returned in the RAX register.
 Randomize: Use a value as the seed of the random number generator.
 Readlnt64: Read a 64-bit signed integer from the keyboard and end with a carriage
return. The value is returned using the RAX register.
 ReadString: Read a string from the keyboard and end with a carriage return. The
process uses RDX to transfer the input buffer offset; uses RCX to transfer the maximum
number of characters that the user can enter plus 1 (for unll terminator byte). The return
value (using RAX) is the number of characters actually entered by the user.
 Str_compare: Compare two strings. The process passes the source string pointer to
RSI, and the destination string pointer to RDI. Set the zero flag and carry flag in the same
way as the CMP (compare) instruction.
 Str_copy: Copy a source string to the location specified by the target pointer. The
source string offset is passed to RSI, and the target offset is passed to RDI.
 Strjength: Use the RAX register to return the length of a null-terminated character
string. The process uses RCX to pass the offset of the string.
 Writelnt64: Display the contents of the RAX register as a 64-bit signed decimal
number, plus a plus or minus sign in front. The procedure did not return a value.
 WriteHex64: Display the contents of the RAX register as a 64-bit hexadecimal
number. The procedure did not return a value.
 WriteHexB: Display the contents of the RAX register as a 1-byte, 2-byte, 4-byte or 8-
byte hexadecimal number. Pass the displayed size (1, 2, 4, or 8) to the RBX register. The
procedure did not return a value.
 WriteString: Display an ASCII string ending with a null byte. Pass the 64-bit offset of
the string to RDX. The procedure did not return a value.

Although this library is much smaller than the 32-bit link library, it still contains many important
tools to make the program more interactive. With the deepening of learning, you can use your
own code to expand this link library. The Irvine64 link library will retain the RBX, RBP, RDI,
RSI, R12, R13, R14, and R15 register values. On the contrary, the RAX, RCX, RDX, R8, R9,
R10 and R11 register values will not be retained.

Practice Code:

ExitProcess proto
WriteString proto
WriteInt64 proto
Str_copy proto
Str_compare proto
Str_length proto
Crlf proto

.data
String1 db "This is my first string",0
String2 db "This is my second string",0
String3 db "Test the length of string",0 ;25 characters
string4 db "Total number of characters in a string: ",0
source_string db "This string is being copied", 0
dest_string db 100 dup(?) ;input buffer for string
total_length dq ?
.code
main proc

;*************************WRITE STRING**********************************
mov rdx, offset string1 ;pass the address of the string to be written in the rdx
call Crlf
call WriteString ;write string to the console
call Crlf ;line ending sequence
Practice Code:

;*************************WRITE STRING**********************************
mov rdx, offset string2 ;pass the address of the string in the rdx
call Crlf
call WriteString ;write string to the console
call Crlf ;line ending sequence

;**************************To Compare Strings********************


mov RSI, offset string1
mov RDI, offset string2
Call Str_compare

;*******************To find the length of string**************


mov rcx, offset string3
call Str_length
mov total_length, rax

;***************To write the total length of string3***********


mov rdx, offset string4 ;pass the address of the string in the rdx
call Crlf ;line ending sequence
call WriteString ;write string to the console

mov rax, total_length


call WriteInt64
call Crlf ;line ending sequence

;*******************************To copy one string to the other************


mov rsi, offset source_string
mov rdi, offset dest_string
Call Str_copy
mov rdx, offset dest_string
call Crlf ;line ending sequence
call WriteString ;write string to the console
call Crlf ;line ending sequence
call ExitProcess
main endp
end

Output:
Perform the following tasks.
1. Find out the total length of a string.
Output:

2. Write a program to check whether two strings are equal or not. Display message
“Both strings are equal, if equal. Otherwise display “Both strings are not equal”.
Output:
Equal

Not equal:

You might also like