## Execution commands of µCsim

### r,run,go [start [stop]]

This command starts the execution of the simulated program.

Parameters are optional. First parameter specifies start address of the execution. By default execution starts at address specified by actual value of the PC. This can be overridden by the first parameter.

If second parameter is specified, it places a dynamic breakpoint at specified address which stops the execution at that address. If stop address is not given the simulator stops if it reaches a breakpoint that was previously set, or the CPU accepts an interrupt and stopit option is TRUE, or fatal error occurs or stop command is used on an other console, or ENTER key is pressed on the console where the run command was issued.

When program execution is started, the console becomes frozen, it is not possible to give commands on this console to the simulator while the execution is running. If it is needed to control the simulator during program execution then more consoles can be used. See using multiple consoles for more information. Meanwhile, simulation can be stopped by pressing ENTER key on the frozen console (where the run command was issused).

Note that first instruction is executed without effect of breakpoints and simulation will be started afterwards. It means that if there is a breakpoint at start address then it will not be hit. See following example:

    $ ./ucsim_51
    ucsim 0.2.38-pre1, Copyright (C) 1997 Daniel Drotos, Talker Bt.
    ucsim comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
    This is free software, and you are welcome to redistribute it
    under certain conditions; type `show c' for details.
    > b 0x10
    Breakpoint 1 at 0x000010: MOV   R7,A
    > b 0x20
    Breakpoint 2 at 0x000020: MOV   R7,A
    > run 0x10
    Warning: maybe not instruction at 0x000010
    Simulation started, PC=0x000010
    Stop at 0x000020: (104) Breakpoint
    F 0x000020
    >

### stop

This command stops the simulation, it freezes the CPU and all the peripherals.

    $ ucsim_51 remoansi.hex
    ucsim 0.2.24, Copyright (C) 1997 Daniel Drotos, Talker Bt.
    ucsim comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
    This is free software, and you are welcome to redistribute it
    under certain conditions; type `show c' for details.
    58659 bytes read from remoansi.hex
    > go
    Simulation started
    > info reg
    000000 00 01 00 14 00 00 5a 47 ......ZG
    000000 00 .  ACC= 0x47  71 G  B= 0x01   DPTR= 0x001c @DPTR= 0x47  71 G
    000001 01 .  PSW= 0x00 CY=0 AC=0 OV=0 P=0
       006f02 90 00 1e MOV   DPTR,#001e
    > stop
       006ac5 24 a5    ADD   A,#a5
    >

After using the stop command, the instruction pointed by PC is disassembled, see the dis command for description of disassembled form.

### s,step [steps]

Step command. It executes one instruction without effect of breakpoints.

The optional parameter can be used to specify number of instructions to execute. Note that breakpoints will stop the execution after the first instruction.

    $ ucsim_51 remoansi.hex
    ucsim 0.2.12, Copyright (C) 1997 Daniel Drotos, Talker Bt.
    ucsim comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
    This is free software, and you are welcome to redistribute it
    under certain conditions; type `show c' for details.
    58659 bytes read from remoansi.hex
    > s
    000000 00 00 00 00 00 00 00 00 ........
    000000 00 .  ACC= 0x00   0 .  B= 0x00   DPTR= 0x0000 @DPTR= 0x00   0 .
    000000 00 .  PSW= 0x00 CY=0 AC=0 OV=0 P=0
       000160 c2 90    CLR   P1.0
    >

After execution of actual instruction pointed by PC (or all instructions specified by the optional parameter) the step command dumps out the register set.

Number of steps can be specified in different units. If no unit is appended to step number then it will be interpreted as number of instruction. Other know units are:

s, sec
  Simulated execution time in seconds.
ms, msec
  Simulated execution time in milliseconds.
us, usec
  Simulated execution time in microseconds.
ns, nsec
  Simulated execution time in nanoseconds.
vclk
  Number of virtual clock counts.
fclk, fetch
  Number of fetches.
rclk, read
  Number of memory read operations.
wclk, write
  Number of memory write operations.

### n,next

Execute until next instruction is reached. This command is similar to step command described above but if actual instruction to execute is a subroutine call the next command places a dynamic breakpoint after the call instruction and starts to execute the subroutine. If the subroutine is infinite the breakpoint set by next will never be reached. It can be a dangerous situation because the execution started by the next command can not be stopped interactively. But it can be stopped by other breakpoints.

    $ ucsim_51 remoansi.hex
    ucsim 0.2.12, Copyright (C) 1997 Daniel Drotos, Talker Bt.
    ucsim comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
    This is free software, and you are welcome to redistribute it
    under certain conditions; type `show c' for details.
    58659 bytes read from remoansi.hex
    > run 0 0x172
       000172 79 04    MOV   R1,#04
    > dis 0x172 0 5
       000170 7f 00    MOV   R7,#00
       000172 79 04    MOV   R1,#04
       000174 12 0d b8 LCALL 0db8
       000177 0f       INC   R7
       000178 d9 fa    DJNZ  R1,0174
       00017a 75 0b 00 MOV   0b,#00
    > n
    000000 00 04 00 00 00 00 00 00 ........
    000000 00 .  ACC= 0x00   0 .  B= 0x00   DPTR= 0x0000 @DPTR= 0x00   0 .
    000004 00 .  PSW= 0x00 CY=0 AC=0 OV=0 P=0
       000174 12 0d b8 LCALL 0db8
    > n
    000000 00 04 00 00 00 00 00 00 ........
    000000 00 .  ACC= 0x00   0 .  B= 0x00   DPTR= 0x0167 @DPTR= 0x00   0 .
    000004 00 .  PSW= 0x00 CY=0 AC=0 OV=0 P=0
       000177 0f       INC   R7
    >

### pc [address]

Using this command without any parameter it simply dumps out instruction pointed by the PC. Specify address if you want to set the PC.

    $ ucsim_51
    S51 0.1.5, Copyright (C) 1997 Daniel Drotos, Talker Bt.
    S51 comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
    This is free software, and you are welcome to redistribute it
    under certain conditions; type `show c' for details.
    > pc
     * 000000 ff       MOV   R7,A
    > pc 123
     * 00007b ff       MOV   R7,A
    > sopt debug t
    > pc 32
    Warning: maybe not instruction at 000020
     * 000020 ff       MOV   R7,A
    >

### history

History command can be used to inspect and manipulate history of executed instructions. It accepts following subcommands:

history
history information
history list
history clear

> #### history

> This command (without a subcommand) prints out last 10 elements of the command history in disassembled form.

>     0> hist
>      ? 0x0211 78          LD      A,B
>      ? 0x0212 de 22       SBC     A,#0x22
>      ? 0x0214 38 f7       JR      C,#-9
>      ? 0x0216 c9          RET
>      ? 0x0109 c3 04 02    JP      #0x0204
>      ? 0x0204 3e 00       LD      A,#0x00
>      ? 0x0206 cf          RST     8
>      ? 0x0008 fb          EI
>      ? 0x0009 ed 4d       RETI
>      ? 0x0207 76          HALT
>     0>

> #### history information

> Print out information about execution history.

>     0> hist info
>     len: 100
>     used: 100
>     insts: 100
>     0>

> Len is size of the history, used shows how many slots are filled, insts is number of the instructions recorded by the history.

> #### history list [nr]
> history print [nr]

> This command is the same as the history command but it accepts a parameter which specifies how many records to print (defaults to 10):

>     0> hist list 3
>      ? 0x0008 fb          EI
>      ? 0x0009 ed 4d       RETI
>      ? 0x0207 76          HALT
>     0> hist list 30
>      ? 0x020e 79          LD      A,C
>      ? 0x020f d6 33       sub     #0x33
>      ? 0x0211 78          LD      A,B
>      ? 0x0212 de 22       SBC     A,#0x22
>      ? 0x0214 38 f7       JR      C,#-9
>      ? 0x020d 03          INC     BC
>      ? 0x020e 79          LD      A,C
>      ? 0x020f d6 33       sub     #0x33
>      ? 0x0211 78          LD      A,B
>      ? 0x0212 de 22       SBC     A,#0x22
>      ? 0x0214 38 f7       JR      C,#-9
>      ? 0x020d 03          INC     BC
>      ? 0x020e 79          LD      A,C
>      ? 0x020f d6 33       sub     #0x33
>      ? 0x0211 78          LD      A,B
>      ? 0x0212 de 22       SBC     A,#0x22
>      ? 0x0214 38 f7       JR      C,#-9
>      ? 0x020d 03          INC     BC
>      ? 0x020e 79          LD      A,C
>      ? 0x020f d6 33       sub     #0x33
>      ? 0x0211 78          LD      A,B
>      ? 0x0212 de 22       SBC     A,#0x22
>      ? 0x0214 38 f7       JR      C,#-9
>      ? 0x0216 c9          RET
>      ? 0x0109 c3 04 02    JP      #0x0204
>      ? 0x0204 3e 00       LD      A,#0x00
>      ? 0x0206 cf          RST     8
>      ? 0x0008 fb          EI
>      ? 0x0009 ed 4d       RETI
>      ? 0x0207 76          HALT
>     0>

> #### history clear

> This command clears the history, it deletes all recorded elements.

>     0> hist list 3
>      ? 0x0008 fb          EI
>      ? 0x0009 ed 4d       RETI
>      ? 0x0207 76          HALT
>     0> hist clear
>     0> hist info
>     len: 100
>     used: 0
>     insts: 0
>     0>