Connect with us

machine language to assembly language

Discussion in 'Microcontrollers, Programming and IoT' started by vead, Aug 23, 2014.

Scroll to continue with content
  1. vead

    vead

    473
    14
    Nov 27, 2011
    everyone say start with basics learn some basic things
    so my another effort for learning about micro controller
    I know about basic gates like AND, NOT and OR,
    we can make following circuits with help of basic gates
    Addition
    Subtraction
    Division
    Multiplication
    Logical AND
    Shift Left
    Shift Right

    suppose we want to add two 8 bit number
    we have to implement 8 bit adder

    example 6+ 2 =8
    00000110
    +00000010
    ------------
    00001000
    ...

    so we can develop many circuit
    Addition
    Subtraction
    Division
    Multiplication
    Logical AND
    Logical NOT
    Logical OR
    Logical XOR
    Shift Left
    Shift Right

    now we have many operation so we want use them
    we want to tell the CPU what operation to do. So, we encode the operations in some bit pattern,
    for example:
    0001 Perform NOT
    0010 Perform AND
    0011 Perform OR
    0100 Perform Addition
    0101 Perform Subtraction
    0110 Perform Multiplication
    0111 Perform Division
    1000 Move bits from memory into registers
    ...
    ...

    Now, suppose we want the CPU to perform addition of 6 and 2,
    the number 6 (0110) and the number 2 (0010), so something like:
    0100 0110 0010
    Now we can start talking about a sequence of operations:
    0100 0110 0010
    01010 010 0010
    0100 0110 0110
    0010 1000 0010
    1000 1010 0010

    machine language is hard to understand so we developed assembly language
    Mov (1000)
    6 (0110)
    mov A, # 6 ( assembly language )
    1000 0110 ( machine language )
    another
    Mov (1000)
    2 (0010)
    mov R1#2 ( assembly language )
    1000 0010 ( machine language )
    8=6+2
    Add A, R1
    0100 0110 0010

    machine language

    1000 0110
    1000 0010
    0100 0110 0010

    assembly language
    mov A, #6
    mov R1,#2
    add A,R1

    I have tried to understand in very low level
    can some explain with example how to convert machine code into assembly code
    I know assembly code convert into machine code but for low level understanding how we developed assembly language to understand machine language
     
  2. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,268
    Nov 28, 2011
    Normally you use a program called a disassembler. This may be a program that runs on a computer that processes a binary or hex file, or it may be a program that runs on the target system and disassembles memory directly.

    You can do it manually as well, if you have an opcode map. The data sheet for the processor will usually have instruction encoding information, and many of them have an opcode map, formatted as a table, that allows you to quickly identify the instruction mnemonic that a particular binary opcode corresponds to.

    Microprocessors often have multi-byte or multi-word instructions so the initial byte or word may not completely specify the instruction. In this case several tables are needed to give the full opcode mapping information.

    What architecture are you working with? If you give some specifics, I can answer with some specifics.
     
  3. vead

    vead

    473
    14
    Nov 27, 2011
    I am talking about 8051 controller
    assembler convert assembly code into machine code

    suppose we have sequence

    1000 101 10 0110
    suppose ( symbolic form )
    Mov (1000) ,
    A (101),
    #(10) ,
    6(0110)
    each assembly symbol converted into machine language

    now we write program in assembly
    mov A, # 6

    and assembler convert this statement into machine language
    1000 101 10 0110
     
  4. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,268
    Nov 28, 2011
  5. vead

    vead

    473
    14
    Nov 27, 2011
    Q1 look at post #3 this is temporary example I have taken for understanding
    Is it true ?

    Q2 look at this test code
    Code:
    1   0000                                  ORG 0H
    2   0000                       Start:
    3   0000   74 05                   MOV A, #5H
    4   0002   79 04                   MOV R1, #4H
    5   0004   29                      ADD A,R1
    6   0005                       nop
    where 74, 79 are operation code or opcode
    I think 5 , 4 are data or operand

    can you tell me what is 0000,0002, 0004 ?
     
  6. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,268
    Nov 28, 2011
    That's right. All of those numbers are in hex. The 0000, 0002, 0004 etc are the memory addresses where those bytes will be placed.
     
  7. vead

    vead

    473
    14
    Nov 27, 2011
    I think its ram address (The 0000, 0002, 0004 etc are the memory addresses) where data will be store
    how we access memory and which instruction we use that determine weather we are accessing Internal rom , Internal Ram or SFR
     
  8. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,268
    Nov 28, 2011
    No, those are ROM addresses; they are the addresses where the instruction opcodes and operands are stored. Code is stored in ROM. RAM is used for variables and stack.
    Are you asking a question or making a statement? That's right. Instruction opcodes and operand bytes are stored in ROM and the MCU processor core gets them from ROM and executes them. For some instructions, the MCU processor core also accesses memory, and the type of memory accessed may be ROM, RAM, or SFRs.
     
  9. vead

    vead

    473
    14
    Nov 27, 2011
    Code:
    1   0000                                  ORG 0H
    2   0000                       Start:
    3   0000   74 05                   MOV A, #5H
    4   0002   79 04                   MOV R1, #4H
    5   0004   29                      ADD A,R1
    6   0005 

    I understood about rom address
    can you explain what is ram location with this code. I have tried but I always confuse
     
  10. Harald Kapp

    Harald Kapp Moderator Moderator

    10,060
    2,146
    Nov 17, 2011
    In your code example no RAM addresses are involved.

    0000, 0002, 0004... are all ROM addresses.
    74 05 = MOV A, #5H - here 74 is the opcode fpr MOV A (move data to register A which is a special register called accumulator) and 05 is the directly attached data (#5H from the assembler listing)
    Equally
    79 04 mean mode direct data #4H to register R1
    and 20 means ADD contents of register R1 to accumulator A and store result in accumulator A.

    Registers are adddressed by names (R1, A, ...) and not by memory adddresses.
     
  11. vead

    vead

    473
    14
    Nov 27, 2011
    Its very hard for me I tried more but I did not learn concept of ram location

    how does cpu use ram location ?
    what instruction is used to access ram location ?
     
  12. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,268
    Nov 28, 2011
    The 8051 uses the Harvard architecture where the data path from the ROM (where instruction opcodes and operand bytes are stored) is independent from the path to the data memory.

    In general, the ROM is used only to provide instruction bytes to the MCU core, and other memory accesses operate on the data memory space. ROM can only be accessed as data using two special instructions called MOVC.

    In the 8051, the directly addressable data memory space is 256 bytes. The bottom half (addresses 0x00~0x7F) corresponds to actual RAM, which contains the internal registers, bit-addressable memory locations, and general purpose RAM, and the top half of the data memory space (addresses 0x80~0xFF) addresses the SFRs.

    All instructions that address memory directly access the data memory space, and can be used to access RAM and SFRs. These instructions include the word "direct" in their names and/or descriptions in the 8051 instruction summary and instruction list.

    This is explained more thoroughly in the data sheet, and in the Wikipedia page at https://en.wikipedia.org/wiki/Intel_MCS-51.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-