Traffic light on Pic12F629 with "incorrect" program. The number of numbers on assembler

When the son glued for the school from the paper of the traffic light, the thought came: "And why not collect for him the acting model of the traffic light on the microcontroller." On the Internet there are many schemes and programs to them, implementing the principle of the simplest traffic light. But they are or too complicated for toys (DC-DC transducer, shift registers, etc.) or are represented only as an example of the simplest program on the assembler. I want to review the scheme and program on the assembler of the completed design of the toy traffic light with some additional features. Moreover, it is collected on a "penny" microcontroller along the simplest scheme, which is important for beginners. I hope this simple scheme It will become for many beginners to study the programming of PIC microcontrollers, the first design actually assembled on the PIC. Simple, but at the same time containing the main techniques and programming attributes, the program will make it easy to understand and experiment with it.

Even who deals with programming microcontrollers, the basic principles of writing handlers are known: as a short time of execution and short code, no cycles and calls from the handler of other subroutines, etc. In this case, interruptions are allowed only to change the level (we cannot miss other interrupts, since they are simply not) and I, to simplify the program and its perception, found it possible to move away from these principles. Here in the interrupt handler there are cycles, and a call to another subprogramme, and (about horror!) Even the transition to Sleep mode. Therefore, in the header, the program is called "wrong". IN this caseThe interrupt handler is used as a regular subprogramme, however, in other cases, the above principles, of course, remain in force.

Brief characteristics of the device:

The device is a model of a street traffic light with a reliable simulation of its operation (flower switching, green blink) and has additional functions: change the switching frequency by pressing the button, the blinking mode is yellow, the transition to sleep mode in manual and automatic mode followed by turning on the button pressing. This device can be used as a children's toy, as well as a visual allowance in children's preschool institutions when teaching children on road behavior.

So, we turn to the description and consideration of the scheme.

The scheme is collected on an inexpensive microcontroller Pic12F629. Directly for LED controls, the conclusions GP0-GP2, GP4, GP5 (legs 7, b, 5, 3, 2) are used, programmed as outputs. LEDs for each direction are combined into serial groups, which allows you to minimize the current consumed. R3-R8 resistors limit LED currents. In the case of a strong difference in the return of LEDs of different colors, you will have to select the appropriate resistors. I, for example, two yellow groups are connected in parallel and connected to one resistor, and the same nominal as the rest and shine even a little brighter than others (returns more).

In this scheme, the LEDs are fed to 1.5 in more than a microcontroller from an additional element (in this case, when the current output is turned off, it does not pass to the microcircuit output, since it is much more voltage to open transitions of two LEDs than 1.5 V (at least 2.5 C). And even with the breakdown of both LEDs (which is unlikely), the current through an internal protective diode on a plus power will be about 7.5 mA, which is much less permissible. The current consumption of LEDs is much higher than the consumption of MK, therefore, the discharge difference of the elements (through one The current consumption of MK does not flow) it is possible to neglect. It is experimentally established that, despite the decrease in current through the LEDs when the battery is discharged, the brightness of their glow remains at an acceptable level in the entire battery voltage range. The diagram is extremely simplified, and there is no voltage stabilizer consuming additional Current, which made it possible to abandon the power switch (current consumption in sleep mode - 1-3 m ka).

The control button of the device operations is connected to the output of the GP3 (leg 4), which in the configuration bits is declared as a digital input. When you press the button, the interrupt occurs in the processing of which the following occurs. With long press (more than 4 s), the device goes into sleep mode. With shorter pressures, there is a sequential switching of the speed of the traffic light in a circle with the indication of the current velocity according to the drawing.

In the last mode (red LEDs are lit), the mode of a yellow flashing signal is turned on. With a long pressing of the button (confirmed by the population of all LEDs), go to normal operation with changing the mode to a new one, if the button is not pressed more than 6 seconds., The mode of operation remains the same as the button is pressed.

Charge elements AA in Sleep mode is enough for no less than a year, which is why the power switch is not provided in the device. The device goes into sleep mode also after 0.5 - 1 hour (depends on the speed of switching colors) without affecting the button. From the SLEEP mode, the output occurs at any press of the button. The microcontroller is powered by outputs 1 and 8. To save conclusions and simplify the design, it is turned on internal generator mode without external elements.

Small explanations for the program that is shown in the investment.

Processing the button pressing is made in the subroutines: Wait_Butt __- Waiting for pressing and registering 6s. Without pressing, Push_Butt __- Registration of the duration of clicking, Wait_Nobutt __- Waiting for a not pressed button. At the moments of changing the status of the traffic light (yellow and blinking green), the output port is read from the table in the TACT__ subroutine (younger or senior semi-cake). Similarly, the status indication when the button is pressed - from the ind__ subroutine. To switch to sleep mode after the operation time, a forced transition occurs to the interrupt processing subroutine by software installation Interrupt flag. Changing the const_min constant, const_reg, const_sl can be changed accordingly, the period of green blinking, the initial mode when connecting the battery, operation time without influencing the transition to Sleep mode.

The printed circuit board is made of one-sided-foil fiberglass and has dimensions of 22x87 mm. Extreme LEDs are set parallel to the board in different directions. The average set one from the part side of the parts, and the other - on the side of the tracks with the output of the conclusions into the openings of the board and fixes them from the parts of the springs of the solder, and on the side of the tracks by soldering to the corresponding tracks.

All resistors with a capacity of 0.125 watts. LEDs can be taken any domestic or imported desirable one type with direct voltage drop at a current of 10 mA about 2 volts. Button - any without fixation. The microcontroller is installed on the block.

The configuration word is entered into memory automatically when the firmware is loaded (in the "bird" installed only in the PWRT point, the remaining items are "reset", in the column "oscillator" installed "intosc GP4"). It is first necessary to read the firmware with a clean chip and write the value of the word at the end of the program memory at 03FF, which is required to configure the frequency of the internal generator of the specific instance of the chip. After downloading to the HEX file program, you must manually prescribe this value to 03FF. IN this device Frequency deviation is not critical, but still you should know that this procedure requires such a procedure. In extreme cases, if the factory value is lost, you can do anything - the program has taken steps for correct work and in this case.

The device is placed in a suitable plastic box. Relevant holes are done under the LEDs in the box and lid. In my embodiment, the traffic light itself and the base with the button and the battery are connected through the segment of the plastic water pipe, with a diameter of 20 mm.

The application has: model, printed circuit board In Lay format, program on MPASM assembler, HEX firmware file.

List of radio elements

Designation A type Nominal number NoteScoreMy notebook
IC1 MK Pic 8-bit

Pic12f629.

1 Dip. In notebook
R1 Resistor

3 com

1 0.125 W. In notebook
R2. Resistor

100 Oh.

1 0.125 W. In notebook
R3-R8. Resistor

200 Oh.

6 0.125 W. In notebook
HL1, HL2, HL9, HL10 Light-emitting diode

AL307A.

4 Red In notebook
HL3, HL4, HL11, HL12 Light-emitting diode

When the son glued for the school from the paper of the traffic light, the thought came: "And why not collect for him the acting model of the traffic light on the microcontroller." On the Internet there are many schemes and programs to them, implementing the principle of the simplest traffic light. But they are or too complicated for toys (DC-DC transducer, shift registers, etc.) or are represented only as an example of the simplest program on the assembler. I want to review the scheme and program on the assembler of the completed design of the toy traffic light with some additional features. Moreover, it is collected on a "penny" microcontroller along the simplest scheme, which is important for beginners. I hope this simple scheme will become for many beginners to study the programming of PIC microcontrollers, the first real-collected design. Simple, but at the same time containing the main techniques and programming attributes, the program will make it easy to understand and experiment with it.

Even who deals with programming microcontrollers, the basic principles of writing handlers are known: as a short time of execution and short code, no cycles and calls from the handler of other subroutines, etc. In this case, interruptions are allowed only to change the level (we cannot miss other interrupts, since they are simply not) and I, to simplify the program and its perception, found it possible to move away from these principles. Here in the interrupt handler there are cycles, and a call to another subprogramme, and (about horror!) Even the transition to Sleep mode. Therefore, in the header, the program is called "wrong". In this case, the interrupt handler is used as a regular subprogramme, however, in other cases, the above principles, of course, remain in force.

Brief characteristics of the device:

The device is a model of a street traffic light with a reliable simulation of its operation (flower switching, blown green) and has additional functions: change the switching frequency by pressing the button, the blinking mode is yellow, the transition to sleep mode in manual and automatic mode followed by turning on the button pressing the button. This device can be used as a children's toy, as well as a visual allowance in children's preschool institutions when teaching children on road behavior.

So, we turn to the description and consideration of the scheme:

The scheme is collected on an inexpensive microcontroller. Directly for LED controls, the conclusions GP0-GP2, GP4, GP5 (legs 7, b, 5, 3, 2) are used, programmed as outputs. LEDs for each direction are combined into serial groups, which allows you to minimize the current consumed. R3-R8 resistors limit LED currents. In the case of a strong difference in the return of LEDs of different colors, you will have to select the appropriate resistors. I, for example, two yellow groups are connected in parallel and connected to one resistor, and the same nominal as the rest and shine even a little brighter than others (returns more).

In this scheme, the LEDs are fed to 1.5 in more than a microcontroller from an additional element (in this case, when the current output is turned off, it does not pass to the microcircuit output, since it is much more voltage to open transitions of two LEDs than 1.5 V (at least 2.5 C). And even with the breakdown of both LEDs (which is unlikely), the current through an internal protective diode on a plus power will be about 7.5 mA, which is much less permissible. The current consumption of LEDs is much higher than the consumption of MK, therefore, the discharge difference of the elements (through one The current consumption of MK does not flow) it is possible to neglect. It is experimentally established that, despite the decrease in current through the LEDs when the battery is discharged, the brightness of their glow remains at an acceptable level in the entire battery voltage range. The diagram is extremely simplified, and there is no voltage stabilizer consuming additional Current, which made it possible to abandon the power switch (current consumption in sleep mode - 1-3 m ka).

The control button of the device operations is connected to the output of the GP3 (leg 4), which in the configuration bits is declared as a digital input. When you press the button, the interrupt occurs in the processing of which the following occurs. With long press (more than 4 s), the device goes into sleep mode. With shorter pressures, there is a sequential switching of the speed of the traffic light in a circle with the indication of the current velocity according to the drawing:

In the last mode (red LEDs are lit), the mode of a yellow flashing signal is turned on. With a long pressing of the button (confirmed by the population of all LEDs), go to normal operation with changing the mode to a new one, if the button is not pressed more than 6 seconds., The mode of operation remains the same as the button is pressed.

Charge elements AA in Sleep mode is enough for no less than a year, which is why the power switch is not provided in the device. The device goes into sleep mode also after 0.5 - 1 hour (depends on the speed of switching colors) without affecting the button. From the SLEEP mode, the output occurs at any press of the button. The microcontroller is powered by outputs 1 and 8. To save conclusions and simplify the design, it is turned on internal generator mode without external elements.

Small explanations for the program, which is provided in the investment:

Processing the button pressing is made in the subroutines: Wait_Butt __- Waiting for pressing and registering 6s. Without pressing, Push_Butt __- Registration of the duration of clicking, Wait_Nobutt __- Waiting for a not pressed button. At the moments of changing the status of the traffic light (yellow and blinking green), the output port is read from the table in the TACT__ subroutine (younger or senior semi-cake). Similarly, the status indication when the button is pressed - from the ind__ subroutine. To go to sleep mode after running time, a compulsory transition to the interrupt handling subroutine by software to install the interrupt flag software is occurring. Changing the const_min constant, const_reg, const_sl can be changed accordingly, the period of green blinking, the initial mode when connecting the battery, operation time without influencing the transition to Sleep mode.

The printed circuit board is made of one-sided-foil fiberglass and has dimensions of 22x87 mm. Extreme LEDs are set parallel to the board in different directions. The average set one from the part side of the parts, and the other - on the side of the tracks with the output of the conclusions into the openings of the board and fixes them from the parts of the springs of the solder, and on the side of the tracks by soldering to the corresponding tracks.

All resistors with a capacity of 0.125 watts. LEDs can be taken any domestic or imported desirable one type with direct voltage drop at a current of 10 mA about 2 volts. Button - any without fixation. The microcontroller is installed on the block.

The configuration word is entered into memory automatically when the firmware is loaded (in the IC-PROG, the "bird" is installed only in the PWRT item, the remaining items "reset", in the "Oscillator" column set "intosc GP4"). It is first necessary to read the firmware with a clean chip and write the value of the word at the end of the program memory at 03FF, which is required to configure the frequency of the internal generator of the specific instance of the chip. After downloading to the HEX file program, you must manually prescribe this value to 03FF. In this device, the frequency deviation is not critical, but still you should know that this microcircuit requires such a procedure. In extreme cases, if the factory value is lost, you can do anything - the program has taken steps for correct work and in this case.

The device is placed in a suitable plastic box. Relevant holes are done under the LEDs in the box and lid. In my embodiment, the traffic light itself and the base with the button and the battery are connected through the segment of the plastic water pipe, with a diameter of 20 mm.

Hello!
I want to show how the program is written to control technological equipment on PLC.
Most often I dealt with the PLC production of Schneider Electric. The Quantum chosen by me for this task is the most powerful and expensive PLC of this manufacturer. It can control the equipment with thousands of signals for traffic lights in real life No one naturally use it.

I have never been involved in the automation of traffic lights, so the algorithm came up with himself. Here it is:
1. Traffic light for adjustable pedestrian crossing. Those. Traffic light for cars, pedestrian traffic lights and a button for pedestrians by clicking, a pedestrian notifies about the desire to move the road.
2. After the start of the program, green for machines and red for pedestrians light up.
3. After pressing the button, the pedestrian starts blinking green for machines, then yellow, then red. After that, green for pedestrians lights up, through set time It starts blinking, the red for pedestrians lights up, then yellow and red lights up for cars, then green.
4. For a predetermined period of time after green on the pedestrian traffic light, pressing the Pedestrian button does not start the transition algorithm. The transition algorithm is started in this case only after the specified time expires.
The PLC programming is conducted in the Unity programming environment in IEC 61131-3 standard languages. IN this standard 5 languages \u200b\u200bare included. For example, I chose the Language of Function Blocks - FBD.
Here is a project browser in Unity:

Configure PLC:


The PLC consists of a mounting panel, a power supply unit (1), a controller (2), a discrete input module 32 of 24V DC signal (4), a discrete input module for 32 DC signal 24V (5). In the real project of mounting panels connected to one controller by various networksmay be tens, and I / O modules are hundreds.
Create variables required types in the variables editor:


Variables affected by I / O modules have an address showing to which basket, the module and the channel is tied a signal.
The program consists of sections performed by each controller scanning cycle in order.
A simplified controller scan cycle looks like this:
1. Read the input signals from the input module to variables with addresses.
2. Performing sections.
3. Recording values \u200b\u200bfrom variables with addresses to output output modules.
4. Transition to claim 1.
Create a Clock section with an impulse generator with a period of 0.5 seconds. The TP unit when the input signal changes from 0 to 1 at the output, it gives the pulse of a given duration.


Here and below the screenshots of the sections are given in the animation mode, and not the edit mode. They are displayed values \u200b\u200bof variable values \u200b\u200bat the current time when connecting to a PLC with a loaded program (numbers for numerical variables, color green (1) -cain (0) for Boolean).
The Main section processes the main logic.
The SR unit sets output to 1 at s1 \u003d 1 and resets output to 0 at r \u003d 1.
The R_TRIG unit sets out the output to 1 scan cycle in 1 when entering the input from 0 to 1 (Front Detector).
Block F_TRIG sets output to 1 scan cycle in 1 when entering the input of 1 to 0 (rear edge detector).
InButton variable, tied to the button of the button, is replaced by section on InButtonFortest in order to change its value on the controller simulator without real equipment.


The Outputs section generates output signals to control the lights of traffic lights.


We download the project to the controller simulator:


The value of any variables can be viewed in the animation table:


But for the convenience of debugging, you can make the operator screen with simple graphics, the animation of which is tied to the variable:

We try moving the road:

I did not expect that to control such a simple object, as a traffic light, it will take 30 blocks.
In the next article I will show you how to write this programUsing all IEC 61131-3 Standard Languages \u200b\u200bat the same time.

UPD. Corrected a mistake in the name of the standard.

(Figures), (panel).

Before creating an application, a description of new components should be studied.

The task. Model the work of the traffic light. When you start the project, the traffic panel must be empty. After pressing the start button, the light bulb starts will begin switching. After pressing the STOP button - the light panel is empty again. Using a timer, to change the traffic signal at equal intervals. In the Speed \u200b\u200bfield, the timer interval is entered.

Project progress

1. Create new project. Save it in a separate folder, name it "traffic lights".

2. Place on the form panel (TSHAPE), two buttons (TButton), a text field (TEDIT), the inscription (TLABEL), TIMER (TTIMER) in accordance with the sample:

This should look like this:

2. We make registration:

Set these properties values \u200b\u200bin the object inspector:

Component Property Value
Form1 Caption Traffic light
Panel1 Caption * Empty *
Shape1 Shape stcircle
Shape2. Shape stcircle
Shape3 Shape stcircle
Label1 Caption Speed
Edit1 TEXT. * Empty *
Button1 Caption Start
Button2. Caption Stop

3. Create an event for Form1 in the OnCreate section - Press the Troytheater

Create an event for Timer1 in the Ontimer section - Press the Troetch

4. Set colors to Figures:

Final type:

5. During the loading of the shape, the timer is turned off, the shapes on the panel become invisible.

Create an FormCreate event handler (twice click on the Form1 component) and insert this code:

vAR K: Integer; Procedure TForm1.Formcreate (Sender: Togject); Begin Timer1.Enabled: \u003d False; Shape1.visible: \u003d false; Shape2.visible: \u003d false; Shape3.visible: \u003d false; end;

6. To switch light bulbs, write the program code in the Timer1Timer event handler. This code will be performed with the interval that the user enters the speed in the field. According to the timer testimony, the bulb number is determined, which should be engaged in this moment.

Twice click on the Timer1 component and insert this code:

6. Write the program code for the Start button. By clicking on the button from the field, the interval for the timer is read, the timer readings are entered, the timer turns on.

Twice click on the Button1 component and insert the code:

procedure TFORM1.Button1Click (Sender: Togject); Begin Timer1.Interval: \u003d StrToint (edit1.text); k: \u003d 0; Timer1.Enabled: \u003d True; end;

7. Write the program code for the stop button. After clicking on the button, the timer must turn off, the light bulbs are again invisible.

Twice click on the Button2 component and insert the code:

procedure TFORM1.Button2Click (Sender: Togject); Begin Timer1.Enabled: \u003d False; Shape1.visible: \u003d false; Shape2.visible: \u003d false; Shape3.visible: \u003d false; end;

8. Run the project. In the Speed \u200b\u200bfield, enter the number 1000 (1000 ms \u003d 1c). Light bulbs of the traffic light will start switching at an interval in one second.

Artem Poznyak, student 10 "a" class of School No. 23, Ekibasbuz

Many believe that Assembler is already obsolete and has not used anywhere, but mostly young people who are not engaged in professionally systemic programming. The development of software, of course, is good, but unlike high-level programming languages, the assembler will teach deeply understanding the work of the computer, optimize work with hardware resources, as well as program any technique, thereby developing in the direction of machine learning. To understand this ancient Yap, first should be practiced with simple programsThat best explain the assembler functionality.

IDE for Assembler.

First question: In which development environment is to program on assembler? The answer is unequivocal - MASM32.. it standard programused for this jap. You can download it on the official website MASM32.COM in the form of an archive that will need to unpack and after run the install.exe installer. As an alternative, you can use FASM, but the code will be significantly different for it.

Before work, the main thing is not to forget to add a PATH line to the system variable:

C: \\ MASM32 \\ Bin

HELLO WORLD program on assembler

It is believed that this basic program In programming that beginners are writing in the first place. Perhaps this approach is not quite faithful, but one way or another allows you to immediately see a visual result:

386 .model flat, stdcall option casemap: none include /masm32/include/windows.inc include /masm32/include/user32.inc include /masm32/include/kernel32.inc includelib /masm32/lib/user32.lib includelib / masm32 / lib / kernel32.lib .data MSG_TITLE DB "TITLE", 0 MSG_MESSAGE DB "Hello World", 0 .Code Start: Invoke MessageBox, 0, AddR MSG_MESSAGE, ADDR MSG_TITLE, MB_OK INVOKE EXITPROCESS, 0 END START

To begin with, launch the QEDITOR.EXE editor in the folder with the MASM32 installed, and in it we write the program code. After we save it as a file with the ".asm" extension, and the Bildim program using the Project menu item → "Build All". If there are no errors in the code, the program is successfully compiled, and at the output we will get a ready-made exe file that will show windows window With the inscription "Hello WORLD".

Addition of two numbers on Assembler

In this case, we look, whether the amount of numbers is zero, or not. If so, then the appropriate message appears on the screen, and, if not, there is a different notification.

486 .model flat, stdcall option casemap: none include /masm32/include/windows.inc include /masm32/include/user32.inc include /masm32/include/kernel32.inc includelib /masm32/lib/user32.lib includelib / masm32 / lib / kernel32.lib include / emasm32/macros/macros.asm USELIB MASM32, COMCTL32, WS2_32 .Data .code start: Mov Eax, 123 MOV EBX, -90 Add Eax, EBX Test Eax, Eax JZ ZERO INVOKE MESSAGEBOX, 0, CHR $ ("in EAX not 0!"), CHR $ ("info"), 0 JMP Lexit Zero: Invoke MessageBox, 0, CHR $ ("in Eax 0!"), Chr $ ("info"), 0 Lexit: INVOKE EXITPROCESS, 0 END START

Here we use the so-called tags and special teams With their use (JZ, JMP, TEST). We will discern more:

  • test - Used for logical comparison of variables (operands) in the form of bytes, words, or double words. For comparison, the command uses logical multiplication, and looks at the bits: if they are equal to 1, then the result bit will be 1, otherwise - 0. If we got 0, the flags are set in conjunction with ZF (Zero Flag), which will be equal to 1 . The following results are analyzed based on ZF.
  • jNZ - In case the ZF flag has not been delivered anywhere, the transition is made on this label. Often this command is applied if the program has comparison operations that somehow affect the ZF result. This includes Test and CMP.
  • jZ - If the ZF flag was still installed, the transition by the label.
  • jMP - regardless of whether there is zf, or not, the transition is made by the label.

The number of numbers on assembler

Primitive program that shows the process of summing up two variables:

486 .model flat, stdcall option casemap: none include /masm32/include/windows.inc include /masm32/include/user32.inc include /masm32/include/kernel32.inc includelib /masm32/lib/user32.lib includelib / masm32 / lib / kernel32.lib include / emasm32/macros/macros.asm USELIB MASM32, COMCTL32, WS2_32 .Data MSG_TITLE DB "TITLE", 0 A DB 1H B DB 2H Buffer DB 128 DUP (?) Format DB "% d", 0 .code start: mov Al, A Add Al, B Invoke WSPrintf, Addr Buffer, Addr Format, Eax Invoke MessageBox, 0, Addr Buffer, Addr MSG_TITLE, MB_OK INVOKE EXITPROCESS, 0 END START

In the assembler in order to calculate the amount, it will be necessary to carry out a lot of action, because the programming language works directly with system memory. Here we mostly manipulate the resources, and independently indicate how much to highlight the variable, in what form to perceive numbers, and where to make them.

Getting the value from the command line on the assembler

One of the important basic actions in programming is to obtain data from the console for their further processing. In this case, we get them from command line and display in the Windows window:

486 .model flat, stdcall option casemap: none include /masm32/include/windows.inc include /masm32/include/user32.inc include /masm32/include/kernel32.inc includelib /masm32/lib/user32.lib includelib / masm32 / lib / kernel32.lib include / emasm32/macros/macros.asm USLIB MASM32, COMCTL32, WS2_32 .Data .Code Start: Call Getcommandline; The result will be placed in EAX PUSH 0 PUSH CHR $ ("Command Line") PUSH EAX; Text for output We take from Eax Push 0 Call MessageBox Push 0 Call ExitProcess End Start

You can also use an alternative method:

486 .model flat, stdcall option casemap: none include /masm32/include/windows.inc include /masm32/include/user32.inc include /masm32/include/kernel32.inc includelib /masm32/lib/user32.lib includelib / masm32 / lib / kernel32.lib include / emasm32/macros/macros.asm USLIB MASM32, COMCTL32, WS2_32 .Data .Code Start: Call Getcommandline; The result will be placed in EAX INVOKE GETCOMMANDLINE INVOKE MESSAGEBOX, 0, EAX, CHR $ ("Command Line"), 0 INVOKE EXITPROCESS, 0 PUSH 0 CALL EXITPROCESS END START

Here is used Invoke - a special macro with which the program code is simplified. During the compilation, the macro commands are transformed into the assembler commands. Anyway, we use a stack - a primitive way to store data, but at the same time very convenient. By STDCALL Agreement, in all WINAPI functions, variables are transmitted through the stack, only in reverse orderand placed in the appropriate EAX register.

Cycles in assembler

Use option:

Data MSG_TITLE DB "TITLE", 0 A DB 1H Buffer DB 128 DUP (?) Format DB "% D", 0 .Code Start: mov Al, a .repeat Inc Al .until Al \u003d\u003d 7 Invoke WSPrintf, Addr Buffer, ADDR Format, Al Invoke MessageBox, 0, Addr Buffer, Addr MSG_TITLE, MB_OK Invoke ExitProcess, 0 END START .DATA MSG_TITLE DB "TITLE", 0 Buffer DB 128 DUP (?) Format DB "% D", 0 .code start: MOV EAX, 1 MOV EDX, 1 .WHILE EDX \u003d\u003d 1 INC EAX .IF EAX \u003d\u003d 7 .Break .endif .endw Invoke WSPrintf, Addr Buffer, Addr Format, Eax Invoke MessageBox, 0, Addr Buffer, Addr MSG_TITLE, MB_OK INVOKE EXITPROCESS, 0

To create a cycle, use the REPEAT command. Next, using Inc increases the value of a variable by 1, regardless of whether it is in random access memoryor in the processor itself. In order to interrupt the operation of the cycle, the ".break" directive is used. It can be how to stop the cycle and continue its action after the "pause". You can also interrupt the execution of the program code and check the REPEAT and WHILE condition using the ".continue" directive.

The amount of array elements on Assembler

Here we summarize the values \u200b\u200bof variables in the array using the "For" cycle:

486 .model flat, stdcall option casemap: none include /masm32/include/windows.inc include /masm32/include/user32.inc include /masm32/include/kernel32.inc includelib /masm32/lib/user32.lib includelib / masm32 / lib / kernel32.lib include /masm32/macros/macros.asm uselib MASM32, COMCTL32, WS2_32 .Data MSG_TITLE DB "TITLE", 0 A DB 1H x DD 0,1,2,3,4,5,6,7, 8,9,10,11 N DD 12 Buffer DB 128 DUP (?) Format DB "% D", 0 .Code Start: Mov Eax, 0 MOV ECX, N MOV EBX, 0 L: Add Eax, X Add EBX, Type X Dec ECX CMP ECX, 0 JNE L INVOKE WSPRINTF, ADDR BUFFER, ADDR Format, Eax Invoke MessageBox, 0, Addr Buffer, Addr MSG_TITLE, MB_OK INVOKE EXITPROCESS, 0 END START

The DEC command, as well as Inc, changes the value of the operand per unit, only in the opposite direction, on -1. But the CMP compares the variables by subtraction: takes one value from the second, and, depending on the result, the corresponding flags puts.

Using the JNE command, the label is based on the label based on the comparison of the variables. If it is negative - there is a transition, and if the operands are not equal to each other, the transition is not carried out.

Assembler is interesting for his presentation of variables, which allows you to do anything with them. Specialist who figured out in all subtleties of this language Programming, owns really valuable knowledge that have many ways to use. One task can be solved the most different waysTherefore, the path will be a thorny, but not less exciting.

POST Views: 767