Thread: Immediate numbers

  1. #1
    Banned
    Join Date
    Apr 2015
    Posts
    596

    Immediate numbers

    Greetings to all !
    I'm just wondering about something really confusing me so much !
    once I'm writing in the compiler for instance visual stodio like this +2 or any immediate number (-5 , +6, etc) (( meaning with immediate number which they are not containers for saving data )), How pc is operating with them?! does the pc save them in register? if so, then they have an address which I can get them back ... but thats wrong and I don't know why , any help please?!

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    1,644
    Literal's like that are stored in the machine language representation of the program itself. So, in a sense they do have an "address", but it's not one you generally have access to.

    It's interesting that you used the proper technical term to describe them in assembly language: immediate.
    Code:
    #include <stdio.h>
     
    int main() {
        int a = 24;
        a += 18;
        printf("%d\n", a);
        return 0;
    }
    Code:
    	.file	"immediate.c"
    	.section	.rodata
    .LC0:
    	.string	"%d\n"
    	.text
    	.globl	main
    	.type	main, @function
    main:
    .LFB0:
    	.cfi_startproc
    	pushq	%rbp
    	.cfi_def_cfa_offset 16
    	.cfi_offset 6, -16
    	movq	%rsp, %rbp
    	.cfi_def_cfa_register 6
    	subq	$16, %rsp
    	movl	$24, -4(%rbp)      # there's the immediate 24
    	addl	$18, -4(%rbp)      # there's the immediate 18
    	movl	-4(%rbp), %eax
    	movl	%eax, %esi
    	movl	$.LC0, %edi
    	movl	$0, %eax
    	call	printf
    	movl	$0, %eax
    	leave
    	.cfi_def_cfa 7, 8
    	ret
    	.cfi_endproc
    A little inaccuracy saves tons of explanation. - H.H. Munro

  3. #3
    Banned
    Join Date
    Apr 2015
    Posts
    596
    Quote Originally Posted by john.c View Post
    Literal's like that are stored in the machine language representation of the program itself. So, in a sense they do have an "address", but it's not one you generally have access to.

    It's interesting that you used the proper technical term to describe them in assembly language: immediate.
    Code:
    #include <stdio.h>
     
    int main() {
        int a = 24;
        a += 18;
        printf("%d\n", a);
        return 0;
    }
    Code:
        .file    "immediate.c"
        .section    .rodata
    .LC0:
        .string    "%d\n"
        .text
        .globl    main
        .type    main, @function
    main:
    .LFB0:
        .cfi_startproc
        pushq    %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
        movq    %rsp, %rbp
        .cfi_def_cfa_register 6
        subq    $16, %rsp
        movl    $24, -4(%rbp)      # there's the immediate 24
        addl    $18, -4(%rbp)      # there's the immediate 18
        movl    -4(%rbp), %eax
        movl    %eax, %esi
        movl    $.LC0, %edi
        movl    $0, %eax
        call    printf
        movl    $0, %eax
        leave
        .cfi_def_cfa 7, 8
        ret
        .cfi_endproc
    but why CPY is just understanding assembly language?! is it designed built in by this language?!

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What's CPY?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Dec 2017
    Posts
    1,644
    I also don't understand what you are saying.

    Perhaps you are unaware that all languages ultimately must become assembly language (actually machine language) before they can run on the computer. That's what the compiler or interpreter do, translate the higher-level language to something that the computer actually understands, its machine language.

    BTW, quoting my post in toto (or at all) adds nothing to your question.
    A little inaccuracy saves tons of explanation. - H.H. Munro

  6. #6
    Banned
    Join Date
    Apr 2015
    Posts
    596
    Quote Originally Posted by laserlight View Post
    What's CPY?
    Sorry I'm meaning CPU

  7. #7
    Registered User
    Join Date
    Dec 2017
    Posts
    1,644
    Quote Originally Posted by RyanC View Post
    Sorry I'm meaning CPU
    Please proofread your posts in the future so you don't waste people's time.
    A little inaccuracy saves tons of explanation. - H.H. Munro

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 03-13-2016, 02:34 PM
  2. Replies: 10
    Last Post: 02-08-2012, 03:17 PM
  3. Replies: 3
    Last Post: 09-08-2010, 10:26 AM
  4. Replies: 5
    Last Post: 12-21-2007, 01:38 PM
  5. Comparing numbers to a list of numbers held in a text file
    By jmajeremy in forum C++ Programming
    Replies: 3
    Last Post: 11-06-2006, 07:56 AM

Tags for this Thread