Home > Enterprise >  The function of this piece of code in the assembly
The function of this piece of code in the assembly

Time:01-21

The below code is a code I found from a site to study about assambly more.But I don't know exactly what do this section of code. For example what do .ORG 140 do? Why 140? Or in this line : .DB 0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F how we write them? from where?

.ESEG ;7segment LUT
.ORG 140
.DB 0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F

CodePudding user response:

.ESEG ;7segment LUT

.ESEG specifies the EEPROM memory section, with a comment on what's the purpose of the data

.ORG 140

This specifies that the following data will start at address 140. The semantics of .org depends on the assembler brand you are using.

.DB 0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F

This are 10 bytes of data in a look-up table (LUT) that describe which segments of a 7-segment display have to be lit to show a specific digit. The digit is used as an index into the array, where indices start at an offset of 0. Hence, the 1st entry encodes which segments have to be lit to show a 0.

Written in binary, at the specified offsets we have the following values:

0 → 011 1111
1 → 000 0110
2 → 101 1011
3 → 100 1111
4 → 110 0110
5 → 110 1101
6 → 111 1101
7 → 000 0111
8 → 111 1111
9 → 110 1111

This means the 7-segment display(s) are "connected" / "wired" to the respective bits as follows:

 0000
5    1
5    1
 6666    
4    2
4    2
 3333

For example, a 4 has bits 1, 2, 5 and 6 on, which is the following pattern that resembles a 4 when lit:

 
5    1
5    1
 6666    
     2
     2

Some 7-segment displays feature a dot at the lower left or lower right, so that decimal fractions like 3.14 can be displayed. In this case one would wire the . to bit 7.

And in order to represent hexadecimal digits A, b, c, d, E and F, one could extend the array in the obvious way like

10 → 111 0111 ; A
11 → 111 1100 ; b
...

For negative numbers, encode - as

− → 100 0000 ; minus
  • Related