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
Explain the function and role of Product Teardown Charts, and describe how engineers utilize them in the reverse engineering pro
inn [45]

Answer:

Product deformulation analysis, also known as “chemical reverse engineering” is the process of analytically breaking down a drug, material, or product’s formulation to separate and determine the specific identity and exact quantity of both its major and minor constituent components. This process can be vital to a wide range of scenarios such as identifying hazardous components in consumer products, determining potential patent infringement, or improving competitive positioning of existing or new product(s).

Explanation:

8 0
3 years ago
Read 2 more answers
Can you tell me important facts about Peggy A. Whitson?
Nat2105 [25]

Answer:

- She’s A Biochemist

- She’s An Accomplished Space Chef

- She holds the record for most time spent in a space station for an American astronaut — of any gender.

- She became the first woman to command the International Space Station twice.

- She made apple pie out of tortillas

6 0
3 years ago
Read 2 more answers
The flow rate of liquid metal into the downsprue of a mold = 0.7 L/sec. The cross-sectional area at the top of the sprue = 750 m
katrin [286]

Answer:

367.43 mm²

Explanation:

Given:

Flow rate, Q = 0.7 L/s

1000 L = 1 m³ = 10⁹ mm³

thus,

1 L = 10⁶ mm³

Therefore,

Q = 0.7 × 10⁶ mm³/s

Cross-sectional area at the top of the sprue = 750 mm²

Length of the sprue = 185 mm

Now,

Velocity = \sqrt{2gh}

where,  g is the acceleration due to gravity = 9.81 m/s²

h is the height through which flow is taking place = 185 mm = 0.185

thus,

Velocity = \sqrt{2\times9.81\times0.185}

or

velocity = 1.9051 m/s = 1905.1 mm/s

Also,

Q = Area × Velocity

thus,

0.7 × 10⁶ = Area × 1905.1

or

Area = 367.43 mm²

3 0
4 years ago
A turbojet aircraft is flying with a velocity of 280 m/s at an altitude of 9150 m, where the ambient conditions are 32 kPa and -
artcher [175]

Answer:

(a) The velocity of the exhaust gases. is 832.7 m/s

(b) The rate of fuel consumption is 0.6243 kg/s

Explanation:

For the given turbojet engine operating on an ideal cycle, the pressure ,temperature, velocity, and specific enthalpy of air at i^{th} state are P_i , T_i , V_i , and h_i , respectively.

Use "ideal-gas specific heats of various common gases" to find the properties of air at room temperature.

Specific heat at constant pressure, c_p = 1.005 kJ/kg.K

Specific heat ratio, k = 1.4

3 0
4 years ago
Select the correct answer.
Ulleksa [173]
The answer is A. Immediately inform her colleague
4 0
3 years ago
Other questions:
  • Water at atmospheric pressure boils on the surface of a large horizontal copper tube. The heat flux is 90% of the critical value
    15·1 answer
  • Hello everyone, how can you draw this drawing?
    13·1 answer
  • Calculate the maximum load that a 7075 series aluminum alloy bar (with a T6 temper heat treatment) can support without permanent
    7·1 answer
  • In adopt me, (Roblox) should I trade my fly ride neon penguin for a car,2 shibu inus and a fly ride neon unicorn?????? This is n
    15·2 answers
  • It is said that Archimedes discovered his principle during a bath while thinking about how he could determine if KingHiero‘s cro
    15·1 answer
  • piston-cylinder assembly contains water vapor, initially at 10 bar and 360 degC. The water undergoes a process where pv=constant
    7·1 answer
  • A drum contains 3 black balls, 5 red balls and 6 green balls. If 4 balls are selected at random what is the probability that the
    6·1 answer
  • A segment of a roadway has a free flow speed of 45 mph and a jam density of 25 ft per vehicle. Determine the maximum flow and at
    12·1 answer
  • Why it is important to clean all mixing equipment out after mixing paint?​
    7·2 answers
  • When would you expect your shadow to be longest?
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!