0% found this document useful (0 votes)
79 views12 pages

C and Assembly

The document compares and contrasts programming in assembly language versus high-level languages like C. It discusses some of the inconveniences of assembly like difficulty of debugging and readability. High-level languages address these issues through features like named variables and abstraction. However, assembly allows for more flexibility and optimized code in some cases. The document also covers the differences between compiled and interpreted languages, with interpreters being more portable across systems but with added execution overhead.

Uploaded by

Aman Grover
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views12 pages

C and Assembly

The document compares and contrasts programming in assembly language versus high-level languages like C. It discusses some of the inconveniences of assembly like difficulty of debugging and readability. High-level languages address these issues through features like named variables and abstraction. However, assembly allows for more flexibility and optimized code in some cases. The document also covers the differences between compiled and interpreted languages, with interpreters being more portable across systems but with added execution overhead.

Uploaded by

Aman Grover
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 12

C V/s Assembly

Inconvenience with Assembly


a. Correctness: Easy to make mistakes when programming in assembly b. Debugging: Hard to find bugs in programs written in assembly c. Programming: Code has to be expressed at a very low level d. Readability: Assembly code is hard to read

Issues resolved by HLL


a. Ability to name values b. Readability of code c. Abstraction of the computer

underlying

Issues with HLL


High level languages are not as flexible as lower level languages. In assembly language, for instance, one can write code specific for a particular task that consists of fewer instructions, or is faster, than the corresponding program in a highlevel language.

Compiler v/s Interpreter


With compilation, the program is first transformed from a high level language into machine code. The machine code version can be directly executed by the hardware. With interpretation however, the program is processed by an interpreter (in other words, the program is input data for the interpreter), which executes it line-by-line, section-by-section, method-by-method. Since the underlying computing hardware executes the interpreter, which then indirectly executes the user program, the extra layer adds execution overhead.

Interpreters are more portable


Once a program is compiled into a particular ISA, it can only run on machines that support that ISA. A program written in language X running through an interpreter, however, can run on any machine in any ISA provided that someone has written an interpreter for language X for that ISA. E.g. Unix Command Shell, LC3

include <stdio.h> define STOP 0 nt main() int counter; int startpoint; rintf(Count down Program); rintf(Enter a positive number);

What would be the output of the program? If second last line is replaced by following what will be the output? printf(%c\n,counter + A); printf(%d\n%d\n,counter, startpoint + counter); printf(%x\n,counter);

Generate a symbol table for the following code. Assume all variables occupy one location in memory. { double ff; char cc ; int ii; char dd; }

Following variable declaration appears in program int r; What value it will be initialized to if it is a)Local variable b) Global variable. Write the LC3 code that would result if the following local variable declarations were compiled using LC-3 C compiler: char c = a; int x = 3;

Given int a = 6; int b= 9; What is the value of the following expression: a |b a && b ++a + b- a=(++b < 3) ? a:b Write a C programe that reads a integer from a keyboard display 1 if it is divisible by 3 or a 0 otherwise. (Do not use conditional expressions)

Variable a and b are both declared locally as long int; Translate the expression a+b into LC3 code, assuming long int occupies two bytes. Assume a is allocated at offset 0 and b is at offset -1 in the activation record of their function. Program contains two variable x=3 and y=4. Write the C statements which will exchange the values. (Do it without using temporary variable)

You might also like