Question

Write a simple C language code using MPLABX IDE that explains an operation then rewrite the...

Write a simple C language code using MPLABX IDE that explains an operation then rewrite the same Code but using assembler code language and explain how the codes work.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

C Code to find the sum of two 8-bit numbers:-

#include<stdio.h>

#include<conio.h>

int main(int argc, char* argv[]){

system("cls");

int x = 0x9;

int y = 0x2;

x = x + y;

printf("The Sum is: %x\n", x);

system("PAUSE");

return 0;

}

The Output is attached below:-

C\CHEGG GITAC++ Programs| Sum.exe The Sum is: b Press any key to continue .. .

The Assembly Code for the same C Code is given below:-

data segment
a db 09h ; load 09h to register a
b db 02h ; load 02h to register b
c dw ? ; store the sum in register c
data ends

code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov al,a ; move the lower order 8 bitsof a to AL
mov bl,b ; move the lower order 8 bitsof b to BL
add al,bl ; add the two 8-bits and store the result back to AL
mov c,ax ; move the result stored in Register A to Register C
int 3
code ends
end start

The Output is attached below:-

E variables size: byte elements:1 edit show as: hex 09h 02h

Please let me know in case of any clarifications required. Thanks!

Add a comment
Know the answer?
Add Answer to:
Write a simple C language code using MPLABX IDE that explains an operation then rewrite the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT