ScholarQuill logoScholarQuillUniversity Notes
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
Study Tools
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
Contact
ScholarQuill logo
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
ScholarQuill logoScholarQuillUniversity Notes
Study PortalCOMP3137Move Integer Number Re…
Ctrl + K
Login
Explore
Search
Semester
Papers
CGPA
    COMP3137

    Computer Organization and Assembly Language

    Progress0 / 73 done
    Topics73
    1Introduction to Computer Organization2Assembly Language3Comparison of Low-Level and High-Level Languages
    4General Purpose and Special Purpose Registers5Introduction and Usage of RAM6Processor7Registers8System Bus9Instruction Execution Cycle10Assembly and Machine Language11Assembler12Linker and Link Libraries13Programmer's View of a Computer System14RISC and CISC Architecture15Physical Address Calculation16Basic Memory Organization17CPU Organization18Top Level View of Computer Function and Interconnection19Assembler Instruction Cycle20Execute Cycle21Interrupts22Interrupt Cycle23Memory Connection24Input/Output Connection25CPU Connection26MASM27MIPS28Defining Data in MASM Assembler29Elements of Assembly Language30Integer Constants31Integer Expressions32Real Number Constants33Character Constants34String Constants35Reserved Words36Identifiers37Directives38Instructions39The NOP (No Operation) Instruction40Adding and Subtracting Integer41INC and DEC Instructions42NEG Instruction43How to Move Integer Number in Register44Adding and Subtracting Numbers in Registers45Declaration and Initialization of Variables46Moving Data from Variable to Register47Data Definition Statement48BYTE and SBYTE Data49WORD and SWORD Data50Defining DWORD and SDWORD Data51Knowledge about Different Data Types52Operations, Array & Loops53Division and Multiplication in Assembly54Jumps Based on Specific Flags55Jumps Based on Equality56Simple Jump Statements57Jumps Based on Specific Condition58Code Examples59Practice on MASM60Procedures61File Operations Procedures62Labels in Procedures63Stack64Runtime Stack65Conditional Control Flow Directives66Compound Expressions67Data Representation & Conversion68Architecture69Data Path70Control Unit71Critical Path72General Principles of Pipelining73Pipelined Y86 Implementations
    7 min read
    Topic 43 of 73
    Topic Study Note Illustration
    43

    How to Move Integer Number in Register

    In assembly language, moving (or copying) data into a register is typically done using the MOV instruction. The MOV instruction is one of the most fundamental and...

    Moving an Integer into a Register in Assembly Language

    In assembly language, moving (or copying) data into a register is typically done using the MOV instruction. The MOV instruction is one of the most fundamental and frequently used instructions in assembly language programming. It is used to transfer data from one location to another, including between registers, memory, and immediate values (constants).

    MOV Instruction Syntax

    The MOV instruction has the following general syntax:

    MOV destination, source
    
    • destination: The register or memory location where the data will be stored (the value that will be moved).
    • source: The data that will be moved to the destination. This can be a register, a memory location, or an immediate value (constant).

    Types of Operands for the MOV Instruction

    1. Register to Register: Moving data between two registers.
    2. Immediate Value to Register: Moving an immediate value (constant) into a register.
    3. Memory to Register: Moving data from a memory location into a register.
    4. Register to Memory: Moving data from a register to a memory location.

    1. Moving an Integer into a Register from an Immediate Value

    An immediate value is a constant (literal) number specified directly in the instruction.

    Syntax:

    MOV register, immediate_value
    

    Example 1: Moving an Immediate Integer into a Register

    MOV AX, 100    ; Move the integer 100 into register AX
    
    • In this example, the value 100 (an immediate integer) is moved into the AX register.

    Example 2: Moving a Negative Integer into a Register

    MOV AX, -50    ; Move the integer -50 into register AX
    
    • Here, -50 (a negative integer) is moved into the AX register.

    Example 3: Using a Hexadecimal Immediate Value

    MOV AX, 0x1A   ; Move the hexadecimal value 0x1A (26 in decimal) into AX
    
    • The value 0x1A is a hexadecimal literal representing the decimal value 26, and it's moved into AX.

    2. Moving an Integer from One Register to Another

    You can move the contents of one register into another register.

    Syntax:

    MOV destination_register, source_register
    

    Example 1: Moving Data Between Registers

    MOV BX, AX     ; Move the value in AX into BX
    
    • In this case, the value stored in AX is copied into the BX register. After this instruction, both AX and BX will have the same value.

    Example 2: Using 32-bit Registers (e.g., EAX, EBX in x86)

    MOV EBX, EAX   ; Move the value in 32-bit register EAX into 32-bit register EBX
    
    • Here, EAX (a 32-bit register) contains an integer, and it is moved into EBX (another 32-bit register).

    3. Moving an Integer from Memory into a Register

    You can load an integer value from a memory location into a register.

    Syntax:

    MOV register, [memory_location]
    
    • memory_location can be a label that represents a memory address or a variable that holds a value.

    Example 1: Moving Data from Memory to Register

    MOV AX, [num]   ; Load the integer at memory location 'num' into register AX
    
    • Here, the value stored at the memory location labeled num is loaded into the AX register.

    Example 2: Using 32-bit Memory Location

    MOV EAX, [myVar] ; Load the value at the memory address 'myVar' into 32-bit register EAX
    
    • This example assumes myVar is a memory location containing a 32-bit integer. The value of myVar is loaded into EAX.

    4. Moving Data from a Register to Memory

    You can also store a value from a register into memory.

    Syntax:

    MOV [memory_location], register
    

    Example 1: Moving Data from Register to Memory

    MOV [num], AX   ; Store the value of AX into memory location 'num'
    
    • The value in AX is stored at the memory location labeled num.

    Example 2: Storing 32-bit Data into Memory

    MOV [myVar], EAX ; Store the value in 32-bit register EAX into memory location 'myVar'
    
    • The value in EAX is stored in the memory location myVar.

    5. Example Program: Moving Integer Values into Registers

    Below is an example program demonstrating various ways of moving integer values into registers.

    section .data
        num1 dw 50         ; Define a word (16-bit integer) with value 50
        num2 dw -30        ; Define a word with value -30
    
    section .text
        global _start
    
    _start:
        ; Moving immediate values into registers
        MOV AX, 100        ; AX = 100 (move immediate value)
        MOV BX, -50        ; BX = -50 (move negative integer)
    
        ; Moving values from memory to registers
        MOV AX, [num1]     ; AX = 50 (load value of num1 into AX)
        MOV BX, [num2]     ; BX = -30 (load value of num2 into BX)
    
        ; Moving values between registers
        MOV CX, AX         ; CX = 50 (move value of AX into CX)
    
        ; Store the value of AX back to memory location num1
        MOV [num1], AX     ; Store the value in AX (50) into memory location 'num1'
    
        ; Exit (Linux system call to exit the program)
        MOV AX, 1          ; Syscall number for exit
        INT 0x80           ; Call kernel
    

    Explanation of the Example Program:

    1. Immediate Value Movement:

      • The program first moves the immediate integer values 100 and -50 into registers AX and BX, respectively.
    2. Memory to Register Movement:

      • The program then moves the integer values from memory locations num1 (which contains 50) and num2 (which contains -30) into registers AX and BX.
    3. Register to Register Movement:

      • The value in register AX is copied into CX.
    4. Register to Memory Movement:

      • Finally, the value in AX (which is 50) is stored back into the memory location num1.

    6. Considerations When Moving Integers

    • Size of Registers: Ensure that the size of the register matches the size of the data being moved. For example, if you want to move a 16-bit integer, use a 16-bit register like AX or BX. For 32-bit values, use EAX or EBX. For 64-bit values (in 64-bit systems), use RAX, RBX, etc.

    • Memory Alignment: In certain architectures, memory must be aligned for efficient access. For example, on x86 systems, 16-bit values should be aligned to even memory addresses, and 32-bit values should be aligned to addresses that are divisible by 4.

    • Immediate Values: When moving immediate values, remember that the number must be within the range that can be represented by the size of the operand. For example, in an 8-bit register, the immediate value should be in the range of -128 to 127 (for signed values).

    Conclusion

    The MOV instruction is crucial for moving integer values into registers in assembly language. It can handle various data types and sources, including immediate values, memory locations, and other registers. By using MOV, you can efficiently transfer data and manipulate it within your program, which is essential for low-level programming, system programming, and performance-critical applications.

    ← Previous topic 42
    NEG Instruction
    Next topic 44 →
    Adding and Subtracting Numbers in Registers

    Past Papers

    Open this section to view and download past papers

    Click on Show Past Papers to load available exam papers.

    Reading Progress
    0%
    7mremaining
    1.1kwords
    Intermediatelevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Computer Organization and Assembly Language