## Memory manipulation commands of μCsim

Every command which changes content of ROM area such as dl or set memory deletes result of code analyser and causes to re-analyse the code.

### file,load "file"

Loads file named file into the simulated code memory. File must contain data in Intel HEX format.

    > file "../../remo.hex"
    55470 words read from ../../remo.hex
    >

Don't forget to enclose file name in quotes to make the parameter to be a string.

### download,dl

Download command. It is same as load above but it reads information from command console which is standard input by default. This command stops read records when it detects an "END" record which is normally the last record. This command has two equivalent forms download and dl.

    $ ucsim_51 -V
    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.
    > do
    :03000000020003F8
    :1000030075812078207600D8FC900000AE83AF8203
    :100013009000001200416005E4F0A380F690009F79
    :1000230012004A9000A312004A9000A712006890A1
    :1000330000AD12006875D0001200B50200B3EF6581
    :10004300827003EE658322E493F8740193F97402DA
    :1000530093FE740393F5828E83E869700122E4931F
    :10006300F6A30880F4E493FC740193FD740293FEF9
    :10007300740393FF740493F8740593F582888312D1
    :100083000041700122E493A3A883A9828C838D820B
    :10009300F0A3AC83AD828883898280E3212100B5FC
    :1000A300212100B5000000B500B5000000B500B582
    :0200B30080FECD
    :1000B5007520117501AA850120750102850120228F
    :00000001FF
    197 bytes loaded
    >

### fill memory_type start end data

Fill memory region with specified data. First parameter specifies memory. Name of the memory must be used, it can be checked using info memory command which lists size and name of all available memories.

start and end parameters specify first and last address of the memory region to be filled.

data parameter specifies the data which is used to fill the memory region.

    $ ucsim_51
    ucsim 0.2.38-pre2, 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.
    > fill xram 12 0x12 0x56
    > dump xram 0 0x20
    0x0000 00 00 00 00 00 00 00 00 ........
    0x0008 00 00 00 00 56 56 56 56 ....VVVV
    0x0010 56 56 56 00 00 00 00 00 VVV.....
    0x0018 00 00 00 00 00 00 00 00 ........
    0x0020 00                      .
    >

### where,Where memory_type data...

Searching for some data in memory. First parameter specifies memory. Name of the memory must be used, it can be checked using info memory command which lists size and name of all available memories.

Other parameters can be mixed list of strings (characters between " and ") and numbers. Strings can contain escape sequences. μCsim merges all parameters together and will search for merged list of values in specified memory.

where command do case unsensitive search while Where command is for case sensitive search.

Search is done in whole memory and all matches are dumped out.

    $ ucsim_51
    ucsim 0.2.38-pre2, 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.
    > set mem xram 20 "Dani d ani D ani dani Dani"
    0x0014 44 61 6e 69 20 64 20 61 Dani d a
    0x001c 6e 69 20 44 20 61 6e 69 ni D ani
    0x0024 20 64 61 6e 69 20 44 61  dani Da
    0x002c 6e 69                   ni
    > where xram "dani"
    0x0014 44 61 6e 69             Dani
    0x0025 64 61 6e 69             dani
    0x002a 44 61 6e 69             Dani
    > Where xram "d ani"
    0x0019 64 20 61 6e 69          d ani
    >

### hole [memory [length [value]]]

Searching for a memory area where all locations are filled with value. By default this command searches rom but any memory can be specified. Areas shorter than specified length (default is 100) will not be listed. Searched value is 0 (zero) by default but other can be specified as the last parameter.

    $ ucsim_51
    uCsim 0.6-pre55, Copyright (C) 1997 Daniel Drotos.
    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.
    0> hole
    0x0000 65535
    0> hole xram
    0> fill xram 0x100 0x1ff 11
    0> hole xram 50 11
    0x0100 255
    0> fill xram 0x500 0x600 11
    0&ht; hole xram 50 11
    0x0100 255
    0x0500 256
    0> rom[0x200]=1
    1
    0> hole
    0x0000 511
    0x0201 65022
    0>

Data of found areas are listed in two columns. First column is the start address of the area in hexadecimal and the second column is area length (in decimal).

### memory

This set of commands can be used to manipulate memory system including chips, address spaces and address decoders.

Subcommands are:

memory create
memory remove
memory info
memory cell

### memory create

This set of commands can be used to create new memory objects. It requires a subcommand, which can be:

memory create chip
memory create addressspace
memory create addressdecoder
memory create banker
memory create bank
memory create bander

> #### memory create chip id size cellsize

> This command creates a chip (array of storage elements). id must be a unique name which will be used to identify the chip in other commands. size is number of storage elements, cellsize is number of bits stored in one element.

> #### memory create as|addressspace|addr|addrs|addrspace|aspace id startaddr size

> This command should never be used. It defines an address space, names it as id, sets its starting address and size. Simulator programs (ucsim_51, ucsim_avr, etc.) define necessary address spaces for themself, so this command is not needed.

> #### memory create ad|addrdec|addrdecoder|addressdec|addressdecoder|adec|adecoder addressspace begin end chip begin

> Address decoder maps a part of the address space to a chip area. addressspace parameter is name of the address space, begin and end specify address range of the address space to be mapped. chip parameter is name of the memory chip and the second begin parameter is the (start of the) chip address where the area is mapped to.

> Address space will be split if a "middle" area is mapped:

>     $ ucsim_51
>     uCsim 0.5.0-pre3, 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.
>     0> i m
>     Memory chips:
>       0x000000-0x00ffff    65536 rom_chip (8,%02x,0x%04x)
>       0x000000-0x00007f      128 iram_chip (8,%02x,0x%02x)
>       0x000000-0x00ffff    65536 xram_chip (8,%02x,0x%04x)
>       0x000000-0x00007f      128 sfr_chip (8,%02x,0x%02x)
>     Address spaces:
>       0x000000-0x00ffff    65536 rom (8,%02x,0x%04x)
>       0x000000-0x00007f      128 iram (8,%02x,0x%02x)
>       0x000080-0x0000ff      128 sfr (8,%02x,0x%02x)
>       0x000000-0x00ffff    65536 xram (8,%02x,0x%04x)
>     Address decoders:
>      0 rom 0x0000 0xffff -> rom_chip 0x0000 activated
>      0 iram 0x00 0x7f -> iram_chip 0x00 activated
>      0 sfr 0x80 0xff -> sfr_chip 0x00 activated
>      0 xram 0x0000 0xffff -> xram_chip 0x0000 activated
>     0> mem cchip myram 0x1000 8
>     0> mem createaddressdecoder xram 1234 2000 myram 15
>     0> i m
>     Memory chips:
>       0x000000-0x00ffff    65536 rom_chip (8,%02x,0x%04x)
>       0x000000-0x00007f      128 iram_chip (8,%02x,0x%02x)
>       0x000000-0x00ffff    65536 xram_chip (8,%02x,0x%04x)
>       0x000000-0x00007f      128 sfr_chip (8,%02x,0x%02x)
>       0x000000-0x000fff     4096 myram (8,%02x,0x%03x)
>     Address spaces:
>       0x000000-0x00ffff    65536 rom (8,%02x,0x%04x)
>       0x000000-0x00007f      128 iram (8,%02x,0x%02x)
>       0x000080-0x0000ff      128 sfr (8,%02x,0x%02x)
>       0x000000-0x00ffff    65536 xram (8,%02x,0x%04x)
>     Address decoders:
>      0 rom 0x0000 0xffff -> rom_chip 0x0000 activated
>      0 iram 0x00 0x7f -> iram_chip 0x00 activated
>      0 sfr 0x80 0xff -> sfr_chip 0x00 activated
>      0 xram 0x0000 0x04d1 -> xram_chip 0x0000 activated
>      1 xram 0x04d2 0x07d0 -> myram 0x00f activated
>      2 xram 0x07d1 0xffff -> xram_chip 0x07d1 activated
>     0>

> It is easy to share chip area between address spaces:

>     $ ucsim_51
>     uCsim 0.5.0-pre3, 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.
>     0> mem createaddressdecoder rom 0 0xfff xram_chip 0xf000
>     0> i m
>     Memory chips:
>       0x000000-0x00ffff    65536 rom_chip (8,%02x,0x%04x)
>       0x000000-0x00007f      128 iram_chip (8,%02x,0x%02x)
>       0x000000-0x00ffff    65536 xram_chip (8,%02x,0x%04x)
>       0x000000-0x00007f      128 sfr_chip (8,%02x,0x%02x)
>     Address spaces:
>       0x000000-0x00ffff    65536 rom (8,%02x,0x%04x)
>       0x000000-0x00007f      128 iram (8,%02x,0x%02x)
>       0x000080-0x0000ff      128 sfr (8,%02x,0x%02x)
>       0x000000-0x00ffff    65536 xram (8,%02x,0x%04x)
>     Address decoders:
>      0 rom 0x0000 0x0fff -> xram_chip 0xf000 activated
>      1 rom 0x1000 0xffff -> rom_chip 0x1000 activated
>      0 iram 0x00 0x7f -> iram_chip 0x00 activated
>      0 sfr 0x80 0xff -> sfr_chip 0x00 activated
>      0 xram 0x0000 0xffff -> xram_chip 0x0000 activated
>     0> rom[0]=0xab
>     171
>     0> xram[0xf000]
>     171
>     0>

> #### memory create banker switcher_addressspace switcher_address switcher_mask banked_addressspace start end

> This command creates a "banker", which is a controllable dynamic address decoder. This means that some part of an address space can be mapped to different chips and the actual map is controlled by a memory location.
> This command specifies the range of the address space and the control.
> Following parameters specify the controller:
> - switcher_addressspace address space where the controller memory location is.
> - switcher_address address of the controller.
> - switcher_mask mask of the bits which select a chip. This parameter specifies, how many banks will be used, so how many chips will be needed.
> Following parameters specify the address space and range which is covered by this address decoder:
> - banked_asddressspace name of the address space which will be banked.
> - start start address of the area, and
> - end and address of the area which will be banked.

> #### memory create bank addressspace begin bank_nr chip begin

> Bank.

> #### memory create bander addressspace begin end chip begin bits_per_chip [distance]

> Bander.

### memory remove|rm|del

This set of commands can be used to remove some memory object. It requires a subcommand, which can be:

memory remove chip

> #### memory remove chip id

### memory info

This command is same as info memory.

### var name [memory addr]

This command assigns a name to a memory location. This name can be used in expressions as variable. If memory is not specified, next yet unnamed location will be used from a special address space, called variables. This address space have 256 locations by default (32 bit each), but the size can be specified using -a option of the simulator program.

    0> var abc
    0> i v abc
    abc variables[0x00] = 00000000
    0> abc=12
    12
    0> expr /b abc
    00000000000000000000000000001100
    0>

Memory location can be specified in two forms:

    0> var vname rom 45
    0> i var vname
    vname rom[0x002d] = 73d4d3c4
    0> var other rom[45]
    0> i v other
    other rom[0x002d] = 73d4d3c4
    0>

### rmvar name

This command removes a variable.

    0> rmvar abc
    No such variable