1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Dovator [93]
3 years ago
5

19. Write a C program that converts an uppercase character to a lowercase character. Declare function char toLower(char ch); to

do the conversion. If ch is not an uppercase character, the function should return ch unchanged. If it is an uppercase character, add the difference of 'a' and 'A' to ch as the return value. (a) Write your program with a global variable for the actual parameter. Translate your C program to Pep/9 assembly language. (b) Write your program with a local variable for the actual parameter. Translate your C program to Pep/9 assembly language
Engineering
1 answer:
Ymorist [56]3 years ago
7 0

Answer:

The program is written in C language and converts an uppercase character to lower case and in the first part of the question it uses global variable for actual parameter then the second part it uses local variable. In both parts after doing the conversion of character, we translate the C program to Pep/9 assembly language.

(a)

#include <stdio.h>

char ch;

void toLower(){

if ( ch <= 'Z' && ch >= 'A' )

ch += 'a' - 'A';

}

int main(){

printf("\nEnter the character in uppercase: ");

scanf("%c", &ch);

toLower();

printf("\nOutput after conversion: %c\n\n", ch);

return 0;

}

Assembly conversion:

.file "toUp.c"

.comm ch,1,1

.text

.globl toLower

.type toLower, @function

toLower:

.LFB0:

.cfi_startproc

pushl %ebp

.cfi_def_cfa_offset 8

.cfi_offset 5, -8

movl %esp, %ebp

.cfi_def_cfa_register 5

movzbl ch, %eax

cmpb $90, %al

jg .L1

movzbl ch, %eax

cmpb $64, %al

jle .L1

movzbl ch, %eax

addl $32, %eax

movb %al, ch

.L1:

popl %ebp

.cfi_def_cfa 4, 4

.cfi_restore 5

ret

.cfi_endproc

.LFE0:

.size toLower, .-toLower

.section .rodata

.align 4

.LC0:

.string "\nEnter the character in uppercase: "

.LC1:

.string "%c"

.align 4

.LC2:

.string "\nOutput after conversion: %c\n\n"

.text

.globl main

.type main, @function

main:

.LFB1:

.cfi_startproc

pushl %ebp

.cfi_def_cfa_offset 8

.cfi_offset 5, -8

movl %esp, %ebp

.cfi_def_cfa_register 5

andl $-16, %esp

subl $16, %esp

movl $.LC0, %eax

movl %eax, (%esp)

call printf

movl $.LC1, %eax

movl $ch, 4(%esp)

movl %eax, (%esp)

call __isoc99_scanf

call toLower

movzbl ch, %eax

movsbl %al, %edx

movl $.LC2, %eax

movl %edx, 4(%esp)

movl %eax, (%esp)

call printf

movl $0, %eax

leave

.cfi_restore 5

.cfi_def_cfa 4, 4

ret

.cfi_endproc

.LFE1:

.size main, .-main

.ident

(b)

#include <stdio.h>

char toLower(char ch){

if ( ch <= 'Z' && ch >= 'A' )

ch += 'a' - 'A';

return ch;

}

int main(){

char input, converted;

printf("\nEnter the character in uppercase: ");

scanf("%c", &input);

converted = toLower(input);

printf("\nOutput after conversion: %c\n\n", converted);

return 0;

}

Assembly Code:

.file "toUp.c"

.text

.globl toLower

.type toLower, @function

toLower:

.LFB0:

.cfi_startproc

pushl %ebp

.cfi_def_cfa_offset 8

.cfi_offset 5, -8

movl %esp, %ebp

.cfi_def_cfa_register 5

subl $4, %esp

movl 8(%ebp), %eax

movb %al, -4(%ebp)

cmpb $90, -4(%ebp)

jg .L2

cmpb $64, -4(%ebp)

jle .L2

movzbl -4(%ebp), %eax

addl $32, %eax

movb %al, -4(%ebp)

.L2:

movzbl -4(%ebp), %eax

leave

.cfi_restore 5

.cfi_def_cfa 4, 4

ret

.cfi_endproc

.LFE0:

.size toLower, .-toLower

.section .rodata

.align 4

.LC0:

.string "\nEnter the character in uppercase: "

.LC1:

.string "%c"

.align 4

.LC2:

.string "\nOutput after conversion: %c\n\n"

.text

.globl main

.type main, @function

main:

.LFB1:

.cfi_startproc

pushl %ebp

.cfi_def_cfa_offset 8

.cfi_offset 5, -8

movl %esp, %ebp

.cfi_def_cfa_register 5

andl $-16, %esp

subl $32, %esp

movl $.LC0, %eax

movl %eax, (%esp)

call printf

movl $.LC1, %eax

leal 30(%esp), %edx

movl %edx, 4(%esp)

movl %eax, (%esp)

call __isoc99_scanf

movzbl 30(%esp), %eax

movsbl %al, %eax

movl %eax, (%esp)

call toLower

movb %al, 31(%esp)

movsbl 31(%esp), %edx

movl $.LC2, %eax

movl %edx, 4(%esp)

movl %eax, (%esp)

call printf

movl $0, %eax

leave

.cfi_restore 5

.cfi_def_cfa 4, 4

ret

.cfi_endproc

.LFE1:

.size main, .-main

.ident

You might be interested in
What is the ILS stand for
Alika [10]

Answer:

Instrument Landing System

Explanation:

The ILS works by sending radio waves from the runway to the aircraft. Which is then intercepted and is used to guide the aircraft onto the runway.

6 0
4 years ago
Read 2 more answers
Quadrilateral ABCD is a rectangle.<br> If m ZADB = 7k + 60 and mZCDB = -5k + 40, find mZCBD.
yuradex [85]

Hope this helps...........

8 0
3 years ago
Find the velocity and rate of flow of water through a rectangular channel of 6m wide and 3m deep when it's running full. The cha
Elza [17]

Answer:

V = 1.5062 m/s

Explanation:

look to the photos

5 0
3 years ago
The polycarbonate shell functions as all of the following except:
krok68 [10]

Answer:

what are the answers expect what?

Explanation:

Polycarbonate is commonly used in eye protection, as well as in other projectile-resistant viewing and lighting applications that would normally indicate the use of glass, but require much higher impact-resistance. Polycarbonate lenses also protect the eye from UV light.

6 0
3 years ago
Which of the following is lost when the computer is turned off? ILL MARK BRAINLEST
Pavel [41]

Answer:

cloud storage is the answer

6 0
3 years ago
Read 2 more answers
Other questions:
  • Summary: Given integer values for red, green, and blue, subtract the gray from each value. Computers represent color by combinin
    15·2 answers
  • Dampers dampers springs are used inside some valve spring to
    10·1 answer
  • Stopping quickly is very important in roller derby. It’s necessary to avoid going out of bounds, to quickly turn and pursue memb
    15·1 answer
  • How do I cancel Trial subscription
    15·1 answer
  • How is the minimum circuit ampacity for an air-conditioning condensing unit calculated?
    7·1 answer
  • Define predictive analysis
    7·1 answer
  • 2. What is the Function of the Camshaft in an Internal Combustion Engine?
    13·1 answer
  • A. State the functions of the followings
    9·1 answer
  • What are the three primary factors on which encryption is based?.
    8·1 answer
  • How is electricity made from fossil fuels such as coal?.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!