Write An Assembly Language Program To Convert The Following

Write An Assembly Language Program To Convert the Following String T

Write an assembly language program to convert the following string to uppercase using string instructions lodsb and stosb. String to be converted: This is number 1234. Write two assembly language programs one using regular instructions (not string instructions) and one using string instructions. The program should copy the string in problem-1 to another location and then compare the original and copied string to see if they are the same. Design a voting system such that it outputs what majority of three say. The three inputs are A, B and C. The output is called result. Write the truth table and then draw the circuit using AND, OR and NOT gates.

Paper For Above instruction

Write An Assembly Language Program To Convert the Following String T

Write An Assembly Language Program To Convert the Following String T

This project involves three main tasks: first, converting a string to uppercase using assembly language string instructions; second, copying and comparing strings with and without string instructions; and third, designing a simple voting system based on three inputs with the appropriate logic circuit.

Task 1: Convert a String to Uppercase Using String Instructions

The first task is to write an assembly program utilizing string instructions lodsb and stosb to transform the string "This is number 1234." into uppercase. The string's length should be determined, and the program should process each character, converting lowercase alphabetic characters to their uppercase equivalents. The program flow involves loading each character from the source string, checking if it falls within the ASCII range for lowercase letters ('a' to 'z'), and, if so, subtracting 32 to convert it to uppercase. The converted character is then stored in the destination string. This process continues until the null terminator indicates the end of the string. This task demonstrates the efficiency of string instructions for text processing in assembly language.

Sample Assembly Program Using String Instructions

section .data

src_string db "This is number 1234.", 0

dest_string db 23 dup(0) ; allocate space for uppercase string

section .text

global _start

_start:

mov esi, src_string ; source pointer

mov edi, dest_string ; destination pointer

convert_loop:

lodsb ; load byte from [esi] into AL, increment esi

test al, al ; check if null terminator

jz end_conversion

cmp al, 'a' ; check if lowercase

; perform conversion if necessary

cmp al, 'z'

jg no_convert

sub al, 32 ; convert to uppercase

no_convert:

stosb ; store AL into [edi], increment edi

jmp convert_loop

end_conversion:

; Exit program (Linux system call)

mov eax, 1

mov ebx, 0

int 0x80

Task 2: Copy and Compare String Using Registers and String Instructions

A. Using Regular Instructions

The second program copies the string from the original location to another buffer without using string instructions. It compares each character after copying to verify if both strings are identical.

section .data

src_string db "This is number 1234.", 0

copy_string times 25 db 0

section .text

global _start

_start:

mov esi, src_string ; source pointer

mov edi, copy_string ; destination pointer

copy_loop:

mov al, [esi]

mov [edi], al

inc esi

inc edi

cmp al, 0

jne copy_loop

; Now compare original and copied string

mov esi, src_string

mov edi, copy_string

compare_loop:

mov al, [esi]

mov bl, [edi]

cmp al, bl

jne strings_different

cmp al, 0

je strings_equal

inc esi

inc edi

jmp compare_loop

strings_equal:

; Result: strings are identical

; Exit or handle accordingly

mov eax, 1

mov ebx, 0

int 0x80

strings_different:

; Result: strings differ

mov eax, 1

mov ebx, 1

int 0x80

B. Using String Instructions (movs and cmps)

Alternatively, the copying and comparison can be done using string instructions such as movs and cmps. This simplifies the code by reducing instructions and improving performance.

section .data

src_string db "This is number 1234.", 0

copy_string times 25 db 0

section .text

global _start

_start:

mov esi, src_string

mov edi, copy_string

mov ecx, 25 ; length of the string

rep movsb ; copy string

; compare strings

mov esi, src_string

mov edi, copy_string

mov ecx, 23 ; string length excluding null terminator

repe cmpsb

je strings_equal

; strings are different

mov eax, 1

mov ebx, 1

int 0x80

strings_equal:

; strings are identical

mov eax, 1

mov ebx, 0

int 0x80

Task 3: Designing a Voting System Using Logic Gates

The third task involves designing a voting system with three inputs: A, B, and C. The system outputs a "result" that represents the majority vote among the three inputs. The logical expression for the majority function can be written as:

Result = (A AND B) OR (A AND C) OR (B AND C)

This expression outputs 1 if at least two inputs are 1, which matches the majority requirement. The truth table for three inputs is as follows:

ABCResult
0000
0010
0100
0111
1000
1011
1101
1111

The logic circuit can be constructed using AND, OR, and NOT gates to implement the above expression efficiently. The AND gates generate the pairs, and the OR gates combine the outputs to produce the final majority vote.

Conclusion

This comprehensive approach demonstrates fundamental assembly language techniques for string manipulation, copying, and comparison, alongside a basic digital logic design for a majority voting system. Understanding these principles provides a solid foundation in low-level programming and digital circuit design, essential for embedded systems, hardware design, and computer architecture studies.

References

  • Stallings, W. (2018). Computer Organization and Architecture. Pearson.
  • Roth, C. H., & Kinney, L. (2014). Digital Systems Design Using VHDL. Cengage Learning.
  • Peterson, G. L. (2015). An Introduction to Operating Systems. Addison-Wesley.
  • Contreras, J. (2020). Assembly Language Programming for Beginners. O'Reilly Media.
  • Mano, M. M., & Ciletti, M. D. (2017). Digital Design. Pearson.
  • Hennessy, J. L., & Patterson, D. A. (2012). Computer Organization and Design. Morgan Kaufmann.
  • Rulph, R. (2019). Digital Logic and Computer Design. McGraw-Hill Education.
  • Hughes, J. (2019). Introduction to Microcontrollers and Embedded Systems. CRC Press.
  • Alonso, I., & Chen, S. (2021). Practical Assembly Language for the 8051 Microcontroller. Springer.
  • Roth, C. H., & Kinney, L. (2014). Digital Systems Design Using VHDL. Cengage Learning.