ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Computer Organization and Assembly Language
    COMP3137
    Progress0 / 73 topics
    Topics
    1. Introduction to Computer Organization2. Assembly Language3. Comparison of Low-Level and High-Level Languages4. Register Types (16-bit): General Purpose and Special Purpose Registers5. Introduction and Usage of RAM6. Processor7. Registers8. System Bus9. Instruction Execution Cycle10. Assembly and Machine Language11. Assembler12. Linker and Link Libraries13. Programmer's View of a Computer System14. RISC and CISC Architecture15. Physical Address Calculation16. Basic Memory Organization17. CPU Organization18. Top Level View of Computer Function and Interconnection19. Assembler Instruction Cycle20. Execute Cycle21. Interrupts22. Interrupt Cycle23. Memory Connection24. Input/Output Connection25. CPU Connection26. MASM27. MIPS28. Defining Data in MASM Assembler29. Elements of Assembly Language30. Integer Constants31. Integer Expressions32. Real Number Constants33. Character Constants34. String Constants35. Reserved Words36. Identifiers37. Directives38. Instructions39. The NOP (No Operation) Instruction40. Adding and Subtracting Integer41. INC and DEC Instructions42. NEG Instruction43. How to Move Integer Number in Register44. Adding and Subtracting Numbers in Registers45. Declaration and Initialization of Variables46. Moving Data from Variable to Register47. Data Definition Statement48. BYTE and SBYTE Data49. WORD and SWORD Data50. Defining DWORD and SDWORD Data51. Knowledge about Different Data Types52. Operations, Array & Loops53. Division and Multiplication in Assembly54. Jumps Based on Specific Flags55. Jumps Based on Equality56. Simple Jump Statements57. Jumps Based on Specific Condition58. Code Examples59. Practice on MASM60. Procedures61. File Operations Procedures62. Labels in Procedures63. Stack64. Runtime Stack65. Conditional Control Flow Directives66. Compound Expressions67. Data Representation & Conversion68. Architecture69. Data Path70. Control Unit71. Critical Path72. General Principles of Pipelining73. Pipelined Y86 Implementations
    COMP3137›Integer Constants
    Computer Organization and Assembly LanguageTopic 30 of 73

    Integer Constants

    5 minread
    925words
    Intermediatelevel

    Integer Constants in Assembly Language

    In assembly language, integer constants refer to fixed numeric values that are used directly in the program. These constants can be expressed in different number systems, and understanding how to define and use them is crucial for working with data in assembly programs. Integer constants are used to perform arithmetic operations, store values, control program flow, and interact with hardware.

    Types of Integer Constants

    Integer constants in assembly language can be written in several numeric bases (radix systems). The most common bases are:

    1. Decimal (Base 10)
    2. Hexadecimal (Base 16)
    3. Binary (Base 2)
    4. Octal (Base 8)

    Let's look at how integer constants are represented in these number systems in assembly language.


    1. Decimal Constants (Base 10)

    Decimal integers are the most straightforward and are written as a sequence of digits without any special prefix. These numbers are understood as base 10 by default.

    • Example:

      MOV AX, 123   ; Load the decimal value 123 into the AX register
      
    • Explanation:
      In this example, 123 is a decimal integer constant, and the instruction moves it into the AX register.


    2. Hexadecimal Constants (Base 16)

    Hexadecimal (or hex) is often used in assembly language because it provides a compact way of representing binary values. In hex, digits range from 0-9 and A-F, where A-F represent the values 10-15.

    • Prefix for Hexadecimal: 0x or sometimes just a $ sign is used in different assemblers. In MASM (Microsoft Macro Assembler), the 0x prefix is commonly used to represent hexadecimal values.

    • Example:

      MOV AX, 0x1F4    ; Load the hexadecimal value 1F4 (decimal 500) into AX
      
    • Explanation:
      0x1F4 is a hexadecimal constant. Hex 1F4 is equal to the decimal value 500 (since 116² + 1516¹ + 4*16⁰ = 500).


    3. Binary Constants (Base 2)

    Binary is the base of machine-level operations. While it can be tedious to work directly with binary numbers, some assemblers allow you to define binary constants.

    • Prefix for Binary: MASM and other assemblers often use the b suffix or 0b prefix to indicate binary constants.

    • Example:

      MOV AX, 0b101010  ; Load the binary value 101010 (decimal 42) into AX
      
    • Explanation:
      0b101010 is a binary constant. Binary 101010 is equal to the decimal value 42 (since 12⁵ + 02⁴ + 12³ + 02² + 12¹ + 02⁰ = 42).


    4. Octal Constants (Base 8)

    Octal numbers are less commonly used today but were historically useful in computer systems. Octal constants use digits 0-7.

    • Prefix for Octal: Some assemblers use 0 to denote octal constants (in older systems, octal constants were typically prefixed by a leading 0).

    • Example:

      MOV AX, 0750    ; Load the octal value 750 (decimal 490) into AX
      
    • Explanation:
      0750 is an octal constant. In octal, 750 is equal to the decimal value 490 (since 78² + 58¹ + 0*8⁰ = 490).


    Representation and Usage in MASM

    In MASM (Microsoft Macro Assembler), the following conventions are typically used to specify the numeric base for constants:

    1. Decimal: Simply use the number (e.g., 123).
    2. Hexadecimal: Use the 0x prefix or the h suffix (e.g., 0x1F4 or 1F4h).
    3. Binary: Use the b suffix (e.g., 101010b).
    4. Octal: Use the leading 0 prefix (e.g., 0750).

    Examples:

    .data
      dec_val  DB 123      ; Decimal integer constant
      hex_val  DB 0x1F4    ; Hexadecimal integer constant (0x1F4 is 500 in decimal)
      bin_val  DB 101010b  ; Binary integer constant (101010b is 42 in decimal)
      oct_val  DB 0750     ; Octal integer constant (0750 is 490 in decimal)
    

    Integer Constants with Directives in MASM

    In assembly language, constants are often stored in data segments and used throughout the program. In MASM, you can define constants using assembler directives like .data and .equ:

    Using .equ to Define Constants:

    The .equ directive allows you to define symbolic names for constants, making your code more readable and easier to maintain.

    • Example:
      MAX_SIZE EQU 1024    ; Define MAX_SIZE as the constant value 1024
      BUFFER_SIZE EQU 0x200 ; Define BUFFER_SIZE as a constant hexadecimal value (512 in decimal)
      
      .data
      buffer DB MAX_SIZE  ; Reserve space for a buffer of size 1024
      

    In this example:

    • MAX_SIZE is a constant with a value of 1024.
    • BUFFER_SIZE is a constant defined in hexadecimal (0x200), which is equivalent to 512 in decimal.
    • The .data segment reserves space for the buffer of size MAX_SIZE.

    Using Integer Constants in Operations

    Integer constants are used in arithmetic operations, control flow decisions, and for addressing memory. For example, you might use constants for indexing an array, comparing values, or performing arithmetic calculations.

    Example of Arithmetic:

    MOV AX, 50         ; Load the constant 50 into AX
    ADD AX, 25         ; Add the constant 25 to AX, result will be 75
    

    Example of Memory Addressing:

    MOV BX, 0x1000     ; Load the hexadecimal constant 0x1000 (4096 in decimal) into BX
    MOV AX, [BX]       ; Access the value stored at memory address 0x1000 and move it into AX
    

    Conclusion

    Integer constants in assembly language are crucial for specifying values that are directly used in your program’s logic and operations. These constants can be written in different number systems, such as decimal, hexadecimal, binary, and octal, each having its specific use case. MASM and other assemblers support flexible syntax for representing constants, allowing for clear and efficient assembly code.

    By understanding how to use integer constants in various formats, you can better manage data, perform arithmetic, and address memory in your assembly programs.

    Previous topic 29
    Elements of Assembly Language
    Next topic 31
    Integer Expressions

    Past Papers

    Open this section to load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time5 min
      Word count925
      Code examples0
      DifficultyIntermediate