Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assembly Language (NASM) problem My teacher gave me a problem about using the same code from the previous assignment, which is read an input file,

Assembly Language (NASM) problem

My teacher gave me a problem about using the same code from the previous assignment, which is read an input file, do ROT13 encoding for that file, and then output to a text file.

This time instead of input and output using int 80h, it should be replace by glibc functions, and other related changes should be made. Also print a character count. This problem requires character I/O, so putchar() and getchar() should be the functions to use (Lecture 15, slide 48). Notice that these functions use type int whereas a character is only one byte. Return values are always in EAX

This is my code for the last assignment:

section .bss Buff resb 1 section .data section .text global _start _start: nop ; This no-op keeps the debugger happy Read: mov eax,3 ; Specify sys_read call mov ebx,0 ; Specify File Descriptor 0: Standard Input mov ecx,Buff ; Pass address of the buffer to read to mov edx,1 ; Tell sys_read to read one char from stdin int 80h ; Call sys_read cmp eax,0; je Exit; cmp byte [Buff],41h ; check if below A in ASCII jb Write; ; if below then stdout cmp byte [Buff],5Ah ; check if above Z in ASCII ja lowercheck ; if above then jump to check if from a-z cmp byte [Buff],4Dh; check if from A-M ja encodehigh; if not jump to encode for N-Z jmp encodelow; jump to encode A-M lowercheck: cmp byte [Buff],61h; check with a in ASCII jb Write; stdout if below cmp byte [Buff],7Ah; check with z in ASCII ja Write; stdout if above cmp byte [Buff],6Dh; check if from a-m ja encodehigh; if not jump to encode for n-z jmp encodelow; jump to encode for a-m encodehigh: sub byte [Buff],0Dh; -13 to encode if from n-z jmp Write; stdout encodelow: add byte [Buff],0Dh; +13 to encode if from a-m Write: mov eax,4 ; Specify sys_write call mov ebx,1 ; Specify File Descriptor 1: Standard output mov ecx,Buff ; Pass address of the character to write mov edx,1 ; Pass number of chars to write int 80h ; Call sys_write... jmp Read ; ...then go to the beginning to get another character Exit: mov eax,1 ; Code for Exit Syscall mov ebx,0 ; Return a code of zero to Linux int 80H ; Make kernel call to exit program

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Oracle Database Architecture

Authors: Thomas Kyte, Darl Kuhn

3rd Edition

1430262990, 9781430262992

More Books

Students also viewed these Databases questions

Question

What is inline XBRL? Please explain.

Answered: 1 week ago