LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-14-2005, 01:26 PM   #1
Mistro116@yahoo.com
Member
 
Registered: Sep 2005
Posts: 118

Rep: Reputation: 15
Memory Question - Curious??


In C, how much code execution can be done with 256 lines of code and 24 bits of memory (including registers)? Can while loops be executed?

Thanks,
Mistro116
 
Old 12-14-2005, 01:43 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Try it and see!

a) gcc -S
<= Generate assembly source
b) objdump -d
<= Analyze binary output
Etc etc

For extra credit, you can play with different optimization switches and see what (if any) difference they make in the resulting code size.

Your .. PSM

PS:
Yes, you can easily write a "while" loop in *one* line of C code and (I imagine) a corresponding dozen or so bytes of object code. Here's a pathological example (exactly one ix86 instruction):

C:
while (1);

ASM:
label1:
jmp label1

Last edited by paulsm4; 12-14-2005 at 01:45 PM.
 
Old 12-14-2005, 02:10 PM   #3
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
24 bits of memory? Probably not much. Are you including ALL registers, or just general-purpose registers? What architecture are you using?
 
Old 12-14-2005, 04:07 PM   #4
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
vi small.c =>
Code:
void mini ()
{
  while (1);
}
cc -S small.c; cat small.s =>
Code:
        .file   "small.c"
        .text
.globl mini
        .type   mini, @function
mini:
        pushl   %ebp
        movl    %esp, %ebp
        nop
.L2:
        jmp     .L2
        .size   mini, .-mini
        .section        .note.GNU-stack,"",@progbits
        .ident  "GCC: (GNU) 3.3.4 (pre 3.3.5 20040809)"
   <= OK: THIS IS PRETTY MUCH THE CODE WE'D EXPECT
cc -c small.c; objdump -d small.o =>
Code:
small.o:     file format elf32-i386
Disassembly of section .text:
00000000 <mini>:
   0:   55                      push   %ebp
   1:   89 e5                   mov    %esp,%ebp
   3:   90                      nop
   4:   eb fe                   jmp    4 <mini+0x4>
   <= HEY: GUESS WHAT?  EXACTLY 24 BYTES!
Sorry - not exactly 24 *bits* ;-)

And for that matter, 24 bytes/bits of *what*? You said something about "registers": registers are part of the CPU; they don't take up any RAM. We're definitely curious why you asked this question...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Curious bash prompt editing question. xconspirisist Linux - Software 3 11-19-2005 07:24 PM
Curious question about Fedora mhelliwell Fedora 2 02-20-2005 03:30 AM
A curious YUM and RPM question woranl Fedora 1 08-11-2004 10:45 PM
Help!?! RH 8 Memory Mapping -High Memory-Virtural Memory issues.. Merlin53 Linux - Hardware 2 06-18-2003 04:48 PM
Memory question luser Linux - General 4 10-17-2002 08:18 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration