0% found this document useful (0 votes)
2 views

ARM Manual

The document provides a detailed procedure for assembly level programming on the ARM Cortex M3 using Keil µVision 5, including steps for creating projects, writing assembly programs for multiplying two 16-bit numbers, checking if a number is odd or even, and interfacing with hardware components like switches, relays, and stepper motors. It also includes algorithms and sample programs for various experiments involving flip-flops and adders using CAD tools. The output and results of each experiment are documented, showcasing the functionality of the implemented programs.

Uploaded by

KRISHNAMMAL N
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

ARM Manual

The document provides a detailed procedure for assembly level programming on the ARM Cortex M3 using Keil µVision 5, including steps for creating projects, writing assembly programs for multiplying two 16-bit numbers, checking if a number is odd or even, and interfacing with hardware components like switches, relays, and stepper motors. It also includes algorithms and sample programs for various experiments involving flip-flops and adders using CAD tools. The output and results of each experiment are documented, showcasing the functionality of the implemented programs.

Uploaded by

KRISHNAMMAL N
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 62

(Assembly Level Programming-ARM Cortex M3)

Software: Keil µvision 5


Software Handling Procedure:
1. Double click on µvision 4 icon in the desktop.

2. Select “New µvision Project” from project


3. Browse and create a new project in the required location.

4. Select the target device(here,LPC1768 from NXP) from the list or type the exact name of the device. Press OK.
5. ”Copy start up to Project folder and add to project file”?- Press NO.

6. In the project window, right click on source and select Add new item to group “source group 1”.
7. Select Asm file and give name of the file with .s extension and press ADD.

8. Type the program in the editor space and save.


9. Translate the program by select the icon from tool bar or from menu bar.

10. If no error,Select “Build” icon from tool bar or from menu bar.
11. Start the debug session from Menu bar.

12. Press OK

13. Press function key F11 or select “step” option under Debug menu for single step execution and verify the output
inregister window/Memory window/xPSR.
EXP.No: ALP TO MULTIPLY TWO 16 BIT NUMBERS
Date:

AIM:

To write and execute and Assembly Language Program to multiply two 16-bit numbers

SOFTWARE REQUIRED:

1. Keil uVision5

ALGORITHM

Multiplication:

1. Get the multiplier in the accumulator.


2. Get the multiplicand in the B register.
3. Multiply A with B.
4. Store the product in memory location.
5. Stop the program.

PROGRAM

AREA Reset, DATA, READONLY


EXPORT Vectors
Vectors
DCD 0X20001000
DCD Reset_Handler;

AREA MULTIPLY, CODE, READONLY


ENTRY
EXPORT Reset_Handler
Reset_Handler
MOV r0,#num1
MOV r1,#num2
MUL r2,r0,r1
LDR r3,=product
STR r2,[r3]
stop B stop
AREA DATA2, DATA, READWRITE
num1 EQU 0XFFFF ;maximum value of 16 bit number
num2 EQU 0XFFFF
product DCD 0X0
END
OUTPUT

(0xFFFF) x(0xFFFF) =0xFFFE0001 in the product memory location.


RESULT
EXP.No: ALP TO FIND WHETHER THE GIVEN 16 BIT NUMBER IS
Date: ODD OR EVEN

AIM:

To write and execute and Assembly Language Program to find the given 16 bit number is Odd or Even.

SOFTWARE REQUIRED:

1. Keil uVision5

PROGRAM:

AREA Reset, DATA, READONLY


EXPORT Vectors
Vectors
DCD 0X20001000
DCD Reset_Handler;

AREA oddeven, CODE, READONLY

res EQU 'o'


resu EQU 'e'

ENTRY
EXPORT Reset_Handler
Reset_Handler
LDR r1,=num
LDR r0,[r1]
RORS r0,#1
BCS l1
MOV r2,#resu
B l2
l1 MOV r2,#res
l2 LDR r3,=result
STR r2,[r3]
stop B stop
AREA data, DATA, READWRITE
num DCW 16
result DCB 0X0
END
OUTPUT:

num=16d.Hence it is EVEN
RESULT
(INTERACING WITH LPC1768 MICROCONTROLLER)

SOFTWARE: Keil µVision 4, Flash Magic


EXP.No: PROGRAMMING AND SIMULATION TO INTERFACE A
Date: SWITCH AND DISPLAY ITS STATUS THROUGH RELAY,
BUZZER & LED

AIM

To Interface a simple Switch and display its status through Relay, Buzzer and LED

BLOCK DIAGRAM

ALGORITHM

1. Configure PORT 1 and PORT 2 as GPIO.


2. Configure the direction of Port 2 as input and Port 1 as output .
3. Read the status of the switch.
4. If the switch is pressed, turn on LED, Relay and Buzzer else turn them off.
5. Repeat from step 3 unconditionally.
PROGRAM

#include<LPC17xx.h>
#define switch 11
#define LED 19
#define relay 28
#define buzzer 27
int main(void)
{
LPC_PINCON->PINSEL3=0x00000000;
LPC_PINCON->PINSEL4=0x00000000;
LPC_GPIO2->FIODIR=0x00000000;
LPC_GPIO1->FIODIR=0xFFFFFFFF;
LPC_GPIO1->FIOCLR=0xFFFFFFFF;
while(1)
{
if (!((LPC_GPIO2->FIOPIN>>switch)& 0x1))
{
LPC_GPIO1->FIOPIN=(1<<LED)|(1<<relay)|(1<<buzzer);
}
else
{
LPC_GPIO1->FIOPIN=(0<<LED)|(0<<relay)|(0<<buzzer);
}
}
}
OUTPUT

When the switch is pressed LED is ON, buzzer is ON and relay is ON.

When the switch is not pressed LED is OFF, buzzer is OFF and relay is OFF.
RESULT
EXP.No: PROGRAMMING AND SIMULATION TO INTERFACE A
Date: STEPPER MOTOR

AIM

Interface a Stepper Motor and rotate it in Clockwise & Anti-clockwise direction.

BLOCK DIAGRAM

LPC1768 TRAINER KIT

ALGORITHM

1. Configure the Port 0 and Port 2 as GPIO.


2. Configure the Port 2 in input direction and Port 0 in output direction.
3. Read the status of the switch 1. If it is pressed, set the direction as 0 for clock wise rotation.
4. Else read the status of switch 2. If it is pressed, set the direction as 1 for anti-clock wise
rotation.
5. If the direction is 0, send the data to energize the stepper motor coils in a sequence A-B-C-D
else in D-C-B-A sequence.
6. Insert an appropriate delay between energizing two consecutive coils.
7. Repeat from steps 3 unconditionally.
PROGRAM

#include<lpc17xx.h>
#define SW1 11
#define SW2 12
void delay(unsigned int x)
{
unsignedinti,j;
for(i=0;i<x;i++)
{f
or(j=0;j<90000;j++);
}}i
nt main(void)
{
unsignedint direct;
LPC_PINCON->PINSEL0=0X00000000;
LPC_PINCON->PINSEL1=0X00000000;
LPC_PINCON->PINSEL4=0X00000000;
LPC_GPIO0->FIODIR=0xFFFFFFFF;
LPC_GPIO2->FIODIR=0X00000000;
LPC_GPIO0->FIOCLR=0X00078000;// CLEAR P0.15 TO p0.18
while(1)
{
if(!((LPC_GPIO2->FIOPIN>>SW1)& 0X1))
{
while(!((LPC_GPIO2->FIOPIN>>SW1) & 0X1));
direct=1;
}
else if(!((LPC_GPIO2->FIOPIN>>SW2) & 0X1))
{
while(!((LPC_GPIO2->FIOPIN>>SW2) & 0X1));
direct=0;
}i
f(direct==1)
{
LPC_GPIO0->FIOPIN=0X00008000;
delay(15);
LPC_GPIO0->FIOPIN=0X00010000;
delay(15);
LPC_GPIO0->FIOPIN=0X00020000;
delay(15);
LPC_GPIO0->FIOPIN=0X00040000;
delay(15);
}
else
{
LPC_GPIO0->FIOPIN=0X00040000;
delay(15);
LPC_GPIO0->FIOPIN=0X00020000;
delay(15);
LPC_GPIO0->FIOPIN=0X00010000;
delay(15);
LPC_GPIO0->FIOPIN=0x00008000;
delay(15);
}}
}
RESULT
Analysis and Synthesis of Sequential and Combinational
Circuits using CAD Tools
EXP.No: ANALYSIS AND SYSNTHESIS OF BASIC FLIP-FLOPS
Date:

AIM

To analysis the functionality of S-R Flip-Flop, J-K Flip-Flop, D Flip-Flop using CAD tools

CIRCUIT DIAGRAM OF S-R FLIP-FLOP

PROCEDURE

1. Apply VCC1 and VCC2, so that clock start button will be enabled. Apply low level voltage to
ground(GND1) and (GND2).

2. Next, start the clock pulse by clicking on the "Clock Start" button and after generation of some clock
pulses stop the clock pulse by clicking on the"clock Stop" button. Click the button "Add to table", to
insert the data.

3. Now apply high voltage to S input and low voltage to R input and set "No of clock pulses" to 1. See the
changes at output(Q and Q) at positive clock edge. Click the button "Add to table", to insert the data.

4. Now apply high voltage to R input and low voltage to S input and start the clock pulse. See the changes
at output(Q and Q) at positive clock edge. Click the button "Add to table", to insert the data.
5. Next,apply low voltage to both the inputs(S and R) and see the changes at output(Q and Q) at positive
clock edge. Click the button "Add to table", to insert the data.

6. Next,apply high voltage to both the inputs(S and R) and start the clock pulse again.See both the
outputs(Q and Q) will be zero. It is "not allowed" condition. Click the button "Add to table", to insert the
data.

7. Click button "Plot" to see the graphical representation of S-R flip flop.
TRUTH TABLE

Clock S R Q Qt+1 State


1 0 0 0 0
1 0 0 1 1 No Change
1 0 1 0 0
RESET
1 0 1 1 0
1 1 0 0 1
SET
1 1 0 1 1
1 1 1 0 X
Intermediate
1 1 1 1 X
0 X X 0 0
No Change
0 X X 1 1
CIRCUIT DIAGRAM OF J-K FLIP-FLOP

PROCEDURE

1. Apply VCC1 and VCC2, so that clock start button will be enabled. Apply low level voltage to
ground(GND1) and (GND2).

2. Next, start the clock pulse by clicking on the "Clock Start" button and after generation of some clock
pulses stop the clock pulse by clicking on the"clock Stop" button .

3. Now apply high voltage to J input and low voltage to K input and set "No of clock pulses" to 1. See the
changes at output(Q and Q) at positive clock edge.

4. Now apply high voltage to K input and low voltage to J input and start the clock pulse. See the changes
at output(Q and Q) at positive clock edge.

5. Next,apply low voltage to both the inputs(J and K) and see the changes at output(Q and Q) at positive
clock edge.

6. Next,apply high voltage to both the inputs(J and K) and start the clock pulse again. See both the
outputs(Q and Q) will be zero. It is "not allowed" condition.
TRUTH TABLE

Clock J K Q Qt+1 State


1 0 0 0 0
1 0 0 1 1 No Change
1 0 1 0 0
RESET
1 0 1 1 0
1 1 0 0 1
SET
1 1 0 1 1
1 1 1 0 1
Toggle
1 1 1 1 0
CIRCUIT DIAGRAM OF D FLIP-FLOP

PROCEDURE

1. Apply VCC1 and VCC2, so that clock start button will be enabled. Apply low level voltage to
ground(GND1) and (GND2).

2. Next, start the clock pulse by clicking on the "Clock Start" button and after generation of some clock
pulses stop the clock pulse by clicking on the"clock Stop" button .

3. Now apply high voltage to D input and set "No of clock pulses" to 1. See the changes at output(Q and
Q) at positive clock edge.

4. Now apply low voltage to D input and start the clock pulse. See the changes at output(Q and Q) at
positive clock edge.
TRUTH TABLE

Clock D Q Qt+1 State


1 0 0 0
1 0 1 0 RESET
1 1 0 1
SET
1 1 1 1
0 0 0 0 No Change
0 0 1 1
0 1 0 0 No Change
0 1 1 1
RESULT
EXP.No: ANALYSIS AND SYSNTHESIS OF ADDERS
Date:

AIM

To analysis the functionality of 4 bit and 8 bit Binary Full adder using CAD tools

CIRCUIT DIAGRAM OF 4 BIT BINARY FULL ADDERS

PROCEDURE

1. Apply high to VCC and low voltage to ground(GND)

2. For all the combinations of the 4 bit inputs A (A3A2A1A0), B (B3B2B1B0) verify that the LEDs are
ON or not.

Note: Red button symbolize as Low (L), Green button symbolize as High (H).
TRUTH TABLE

A B SUM
A0 A1 A2 A3 B0 B1 B2 B3 C4 S3 S2 S1 S0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 1 0 0 0 1 0
0 0 1 0 0 0 1 0 0 0 1 0 0
0 0 1 1 0 0 1 1 0 0 1 1 0
0 1 0 0 0 1 0 0 0 1 0 0 0
0 1 0 1 0 1 0 1 0 1 0 1 0
0 1 1 0 0 1 1 0 0 1 1 0 0
0 1 1 1 0 1 1 1 0 1 1 1 0
1 0 0 0 1 0 0 0 1 0 0 0 0
1 0 0 1 1 0 0 1 1 0 0 1 0
1 0 1 0 1 0 1 0 1 0 1 0 0
1 0 1 1 1 0 1 1 1 0 1 1 0
1 1 0 0 1 1 0 0 1 1 0 0 0
1 1 0 1 1 1 0 1 1 1 0 1 0
1 1 1 0 1 1 1 0 1 1 1 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1
Circuit Diagram of 8 bit Binary Full adder

PROCEDURE

1. Apply high to VCC and low voltage to ground (GND)

2. For all the combinations of the 8 bit inputs A ( A7,A6,A5,A4,A3,A2,A1,A0),B


( B7,B6,B5,B4,B3,B2,B1,B0) verify that the LEDs are ON or not.

3. Enter binary input A=10011011 (Decimal value is 155), B=10011011 (Decimal value is 155). Check
output S=100110110 (C8, S7, S6, S5, S4, C4, S3, S2, S1, S0).

4. Enter other input combination of A and B.

Note: Red button symbolize as Low (L), Green button symbolize as High (H).
TRUTH TABLE

A B SUM
A7 A6 A5 A4 A3 A2 A1 A0 B7 B6 B5 B4 B3 B2 B1 B0 C8 S7 S6 S5 S4 S3 S2 S1 S0
RESULT
Network Simulators Communication Topology of network
using NS2 / any simulators.
EXP.No: IMPLEMENTATION OF STAR TOLOGYUSING CISCO NETWORK
Date: SIMULATOR

AIM

To Implement Star Topology using Switches in Cisco Network Simulator

PROCEDURE

Step 1: We have taken a switch and linked it to six end devices.

Step 2: Link every device with the switch.

Step 3: Provide the IP address to each device.

Step 4: Transfer message from one device to another and check the Table for Validation.
OUTPUT

Step 1: We have taken a switch and linked it to six end devices.

Step 2: Link every device with the switch.


Step 3: Provide the IP address to each device.

Step 4: Transfer message from one device to another and check the Table for Validation.

Command:

"ping ip_address_of _any_device"

Example:

ping 192.168.1.4

Note: If the connections are correct then you will receive the response.
RESULT
EXP.No: CONNECTING MULTIPLE COMPUTERS USING HUB
Date:

AIM

To Connect Multiple Computers using Hub in Cisco Network Simulator

PROCEDURE

Step 1: Open the Cisco Packet Tracer.

Step 2: On opening Cisco packet tracer, click on End devices from bottom left icon menus, Add
four PCs and a hub into the screen of the simulator.

Step 3: Connect all PCs and hub with copper straight cable by selecting it through the cables
menu from the bottom left menus in the simulator. Green signal in the wire shows they’re ready to
communicate.

Step 4: Now, we’ve to give unique IP address to each PC. Click on each PC, go to Desktop
section and then click on IP configuration to give IP address.

Step 5: Click on a PC, go to Desktop and then click on Command prompt.

Step 6: After that test the ping command in command prompt to check the connectivity between
these PCs.

Step 7: If ping command works successfully, then it means all these PCs are able to
communicate and share data between them and we’ve build our network of four PCs and a Hub
successfully.
OUTPUT

Step 1: Open the Cisco Packet Tracer.

Step 2: On opening Cisco packet tracer, click on End devices from bottom left icon menus, Add
four PCs and a hub into the screen of the simulator.

Step 3: Connect all PCs and hub with copper straight cable by selecting it through the cables
menu from the bottom left menus in the simulator. Green signal in the wire shows they’re
ready to communicate.
Step 4: Now, we’ve to give unique IP address to each PC. Click on each PC, go to Desktop section
and then click on IP configuration to give IP address.

Step 5: Click on a PC, go to Desktop and then click on Command prompt.

Step 6: After that test the ping command in command prompt to check the connectivity between
these PCs.

For eg : ping 192.168.1.3

Step 7: If ping command works successfully, then it means all these PCs are able to communicate
and share data between them and we’ve build our network of four PCs and a Hub
successfully.
RESULT
Simulation and Programming
Environment Using MATLAB
EXP.No: SIMULATION & PROGRAMMING OF FIR FILTERS USING MATLAB
Date:

AIM

To Program and Simulate FIR filter using MATLAB

SOFTWARE USED

MATLAB

PROGRAM

clear mlhdlc_sfir;
T = 2;
dt = 0.001;
N = T/dt+1;
sample_time = 0:dt:T;
df = 1/dt;
sample_freq = linspace(-1/2,1/2,N).*df;

% input signal with noise


x_in = cos(2.*pi.*(sample_time).*(1+(sample_time).*75)).';

% filter coefficients
h1 = -0.1339; h2 = -0.0838; h3 = 0.2026; h4 = 0.4064;
len = length(x_in);
y_out = zeros(1,len);
x_out = zeros(1,len);
for ii=1:len
data = x_in(ii);

% call to the design 'mlhdlc_sfir' that is targeted for hardware


[y_out(ii), x_out(ii)] = mlhdlc_sfir(data, h1, h2, h3, h4);
end

figure('Name', [mfilename, '_plot']);


subplot(3,1,1);
plot(1:len,x_in,'-b');
xlabel('Time (ms)')
ylabel('Amplitude')
title('Input Signal (with noise)')
subplot(3,1,2); plot(1:len,y_out,'-b');
xlabel('Time (ms)')
ylabel('Amplitude')
title('Output Signal (filtered)')
freq_fft = @(x) abs(fftshift(fft(x)));
subplot(3,1,3); semilogy(sample_freq,freq_fft(x_in),'-b');
hold on
semilogy(sample_freq,freq_fft(y_out),'-r')
hold off
xlabel('Frequency (Hz)')
ylabel('Amplitude (dB)')
title('Input and Output Signals (Frequency domain)')
legend({'FilterIn', 'FilterOut'}, 'Location','South')
axis([-500 500 1 100])
OUTPUT
RESULT
EXP.No: SIMULATION & PROGRAMMING OF TEMPERATURE SENSOR
Date: MEASUREMENT USING MATLAB

AIM

To Program and Simulate Temperature Sensor measurement using MATLAB

SOFTWARE USED

MATLAB

PROGRAM

function sensor Measurement Simulation()

% Simulation parameters
numReadings = 100; % Number of sensor readings
samplingRate = 1; % Time interval between readings (in seconds)
ambientTemperature = 25; % Ambient temperature (baseline value)

% Generate time vector for the readings


time = (0:numReadings-1) * samplingRate;

% Simulate sensor measurements (example: sinusoidal variation around ambient temperature)


amplitude = 5; % Amplitude of the temperature variation
period = 20; % Time period of the sinusoidal variation (in seconds)
temperatureReadings = ambientTemperature + amplitude * sin(2*pi*time/period);

% Add some random noise to the readings to make it more realistic (optional)
noiseAmplitude = 1;
temperatureReadings = temperatureReadings + noiseAmplitude * randn(1, numReadings);

% Plot the simulated sensor measurements


plot(time, temperatureReadings, 'b', 'LineWidth', 2);
xlabel('Time (seconds)');
ylabel('Temperature (°C)');
title('Temperature Sensor Measurement Simulation');
grid on;
end
OUTPUT
RESULT
Study of Free Real Time Operating Systems (RTOS) with ARM Processor/
Microcontroller

Real-Time Operating Systems (RTOS) are specialized operating systems designed to meet the stringent
timing requirements of real-time applications. They are commonly used in embedded systems and
microcontrollers, including those based on ARM processors. One popular RTOS for ARM-based
microcontrollers is FreeRTOS (Free Real-Time Operating System). Let's take a closer look at FreeRTOS in the
context of ARM processors/microcontrollers.

Free RTOS with ARM Processor/Microcontroller:

1. Overview of FreeRTOS:

FreeRTOS is an open-source, real-time operating system kernel that is small, portable, and easy to use.
It was developed by Richard Barry and is widely adopted in various industries, including automotive,
industrial automation, consumer electronics, and IoT devices.

2. Portability:

FreeRTOS is designed to be highly portable, allowing it to run on various microcontroller architectures,


including ARM Cortex-M, ARM7, ARM9, and many others. The portable layer of FreeRTOS abstracts
hardware-dependent details, making it relatively straightforward to adapt to different microcontroller
families.

3. Task Scheduling:

FreeRTOS provides a preemptive, priority-based task scheduler. Tasks are lightweight, independent
threads of execution that are scheduled by the RTOS kernel. Each task is assigned a priority, and the
scheduler ensures that tasks with higher priorities preempt lower-priority tasks when necessary.

4. Kernel Objects:

FreeRTOS offers various kernel objects, such as tasks, queues, semaphores, mutexes, and timers, which
enable communication, synchronization, and resource management among tasks. These kernel objects
are essential for implementing multi-threaded real-time applications.

5. Memory Management:

FreeRTOS provides several memory allocation schemes, including dynamic memory allocation and
static memory allocation at compile time. This flexibility allows developers to choose the most
appropriate memory management method for their specific application requirements.

6. Real-Time Features:

FreeRTOS is designed to be deterministic and predictable, making it well-suited for real-time


applications. It offers features like task priorities, interrupt handling, and accurate timing functions,
allowing developers to meet tight deadlines and respond promptly to time-critical events.
7. Integration with ARM Development Tools:

FreeRTOS is commonly used with ARM development tools, such as Keil MDK (Microcontroller
Development Kit) or the ARM GCC toolchain. These tools provide an integrated development
environment, compilers, and debuggers, streamlining the development process for ARM-based
microcontrollers.

8. Community and Support:

FreeRTOS has a large and active user community, which means developers can find extensive
documentation, tutorials, and examples to get started quickly. Additionally, there are frequent updates
and bug fixes driven by community contributions.

Experiment Setup:

Step 1: Install the necessary tools and IDE for your chosen ARM microcontroller platform.

Step 2: Download the FreeRTOS source code and documentation from the FreeRTOS website
(https://www.freertos.org/).

Step 3: Configure FreeRTOS for your specific ARM microcontroller. The configuration involves setting
the number of tasks, the stack size for each task, and other parameters based on your application
requirements. The FreeRTOS documentation provides detailed instructions on how to configure the
kernel.

Step 4: Write the application code. Create one or more tasks that will run concurrently and perform
specific tasks. For this experiment, we will create two tasks, TaskA and TaskB, each toggling a GPIO
pin at different rates.

Step 5: Compile the code and flash it onto the ARM microcontroller using the appropriate tool chain and
flashing utility.

Step 6: Observe the behavior of the system. In this experiment, TaskA and TaskB are running
concurrently, and you should see the LEDs blinking at different rates (500ms and 1000ms) as defined in
their respective tasks. The real-time behavior of FreeRTOS ensures that tasks run as expected and meet
their timing requirements.

Step 7: Experiment with different task priorities, delays, and other configurations to understand how
FreeRTOS handles task scheduling and real-time performance.
EXP.No: ADDITION OF TWO BINARY NUMBERS IN C
Date:

AIM

Add two binary numbers and find the sum and carry using C programing.

SOFTWARE USED

C Language

PROGRAM

#include <stdio.h>

int main() {

long binary1=10000, binary2=10000;

int i = 0, remainder = 0, sum[20];

while (binary1 != 0 || binary2 != 0)

sum[i++] =(binary1 % 10 + binary2 % 10 + remainder) % 2;

remainder =(binary1 % 10 + binary2 % 10 + remainder) / 2;

binary1 = binary1 / 10;

binary2 = binary2 / 10;

if (remainder != 0)

sum[i++] = remainder;

printf("Sum of two binary numbers: ");

while (i >= 0)

printf("%d", sum[i--]);

return 0;

}
OUTPUT

Sum of two binary numbers: 100000


RESULT
EXP.No: SUBTRACTION OF TWO BINARY NUMBERS IN C
Date:

AIM

Add two binary numbers and find the sum and carry using C programing.

SOFTWARE USED

C Language

PROGRAM

#include <bits/stdc++.h>

using namespace std;

// function to subtract two values

// using 2's complement method

int Subtract(int a, int b)

int c;

// ~b is the 1's Complement of b

// adding 1 to it make it 2's Complement

c = a + (~b + 1);

return c;

// Driver code

int main()

int a = 2, b = 3;

cout << Subtract(a, b)<<endl;


a = 9; b = 7;

cout << Subtract(a, b);

return 0;

}
OUTPUT

-1

2
RESULT

You might also like