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
Is santa real or nah is santa real or nah
Elena L [17]

Answer:

nah

Explanation:

3 0
3 years ago
Read 2 more answers
section 10.1 describes a man in the middle attack on the diffie-hellman key exhange protocal in which the adversary generates tw
nika2105 [10]

Answer:

1. James will attack by generating a random private key XD and a corresponding public key YD.

2. Jane transmit YA to another person called Alex.

3. James intercept YA and transmit YD to jane.

4. Jane receive YD and calculate K1

At this point james and jane thinks they share a secret key but instead james has a secret key k1 to Jane and k2 to alex.

5. Alex transmit another key XA to alex for example.

6. James intercept and calculate k2 and vice versa.

6 0
4 years ago
Two production methods are being compared. One manual and the other automated. The manual method produces 10 pc per hour and req
Genrish500 [490]

Answer:

Check the explanation

Explanation:

Kindly check the attached image below to see the step by step explanation to the question above.

6 0
4 years ago
Please help this is due today!!!!!
White raven [17]

Answer:

1:c 2:False

Explanation:

7 0
3 years ago
Chlorine is one of the important commodity chemicals for the global economy. Before the advent of large scale
artcher [175]

The composition of gas in the feed, the percentage conversion and the

theoretical yield are combined to give the product stream composition.

Response:

The composition of gas in the product stream are;

  • HCl: 0.4 kmol/h, Cl₂: 1.6 kmol/h, H₂O: 1.6 kmol/h, O₂: 0.5 kmol/h

<h3>How can percentage conversion give the contents of the product stream?</h3>

The amount of oxygen used = 30% exceeding the theoretical amount

Number of moles of hydrochloric acid = 4 kmol/h

Percentage conversion = 80%

Required:

The composition of the gas in the product feed.

Solution;

The given reaction is; 4HCl + O₂ \longrightarrow 2Cl₂ + 2H₂O

Percentage \ conversion = \mathbf{ \dfrac{Moles \ of \ limiting \ reactant \ reacted}{Moles \  of \ limiting \ reactant \ supplied \ in \ the \, feed}}

Which gives;

80 \% = \mathbf{ \dfrac{Moles \ of \ limiting \ reactant \ reacted}{4 \, kmol/h}}

Moles of limiting reactant reacted = 4 kmol/h × 0.80 = 3.6 kmol/h

Which gives;

Number of moles of HCl in the stream = 4 kmol/h - 3.6 kmol/h = 0.4 kmol/h

Number of moles of Cl₂ produced = 2 kmol/h × 0.8 = 1.6 kmol/h

Similarly;

Number of moles of H₂O produced = 2 kmol/h × 0.8 = 1.6 kmol/h

Number of moles of O₂ in the product stream = 30% × 1 kmol/h + 20% × 1 kmol/h = 0.5 kmol/h

The composition of the production stream is therefore;

  • <u>HCl: 0.4 kmol/h</u>
  • <u>Cl₂: 1.6 kmol/h</u>
  • <u>H₂O: 1.6 kmol/h</u>
  • <u>O₂: 0.5 kmol/h</u>

Learn more about theoretical and actual yield here:

brainly.com/question/14668990

brainly.com/question/82989

7 0
3 years ago
Other questions:
  • Consider a plane composite wall that is composed of two materials of thermal conductivities kA = 0.1 W/m*K and kB = 0.04 W/m*K a
    13·1 answer
  • Here u go vagdhf dis day did. Du video ioi Hi I gotta go to do something fun to do something that would you want to me see you l
    15·1 answer
  • g The pump inlet is located 1 m above an arbitrary datum. The pressure and velocity at the inlet are 100 kPa and 2 m/s, respecti
    8·1 answer
  • Dunno what to ask, okbye
    5·1 answer
  • What is the angular velocity (in rad/s) of a body rotating at N r.p.m.?
    13·1 answer
  • When handling chemicals and solvents, technicians are recommended to
    10·2 answers
  • A solid cylindrical workpiece made of 304 stainless steel is 150 mm in diameter and 100 mm is high. It is reduced in height by 5
    12·1 answer
  • In a wire, when elongation is 4 cm energy stored is E. if it is stretched by 4 cm, then what amount of elastic potential energy
    15·2 answers
  • What should you consider when choosing the type of hearing protection you use?
    15·1 answer
  • Tech A says that coolant circulates through some intake manifolds to help warm them up. Tech B says that some intake manifolds u
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!