blob: a3830747364536ca1cd3d1feeba52a9ea1359a0f [file] [log] [blame]
Heinrich Schuchardt50cd4ce2022-11-13 13:27:32 +01001.. SPDX-License-Identifier: GPL-2.0+:
2
Heinrich Schuchardt1b0c3162024-01-14 14:53:13 +01003.. index::
4 single: cmp (command)
5
Heinrich Schuchardt50cd4ce2022-11-13 13:27:32 +01006cmp command
7===========
8
9Synopsis
10--------
11
12::
13
14 cmp [.b, .w, .l, .q] addr1 addr2 count
15
16Description
17-----------
18
19The cmp command is used to compare two memory areas. By default it works on
Heinrich Schuchardt8527b022022-11-17 13:42:04 +010020four byte (32-bit) values. By appending .b, .w, .l, .q the size of the
21values is controlled:
Heinrich Schuchardt50cd4ce2022-11-13 13:27:32 +010022
23cmp.b
Heinrich Schuchardt8527b022022-11-17 13:42:04 +010024 compare 1 byte (8-bit) values
Heinrich Schuchardt50cd4ce2022-11-13 13:27:32 +010025
26cmp.w
Heinrich Schuchardt8527b022022-11-17 13:42:04 +010027 compare 2 byte (16-bit) values
Heinrich Schuchardt50cd4ce2022-11-13 13:27:32 +010028
29cmp.l
Heinrich Schuchardt8527b022022-11-17 13:42:04 +010030 compare 4 byte (32-bit) values
Heinrich Schuchardt50cd4ce2022-11-13 13:27:32 +010031
32cmp.q
Heinrich Schuchardt8527b022022-11-17 13:42:04 +010033 compare 8 byte (64-bit) values
Heinrich Schuchardt50cd4ce2022-11-13 13:27:32 +010034
35The parameters are used as follows:
36
37addr1
38 Address of the first memory area.
39
40addr2
41 Address of the second memory area.
42
43count
44 Number of bytes to compare (as hexadecimal number).
45
46Example
47-------
48
49In the example below the strings "Hello world\n" and "Hello World\n" are written
50to memory and then compared.
51
52::
53
54 => mm.b 0x1000000
55 01000000: 00 ? 48
56 01000001: 00 ? 65
57 01000002: 00 ? 6c
58 01000003: 00 ? 6c
59 01000004: 00 ? 6f
60 01000005: 00 ? 20
61 01000006: 00 ? 77
62 01000007: 00 ? 6f
63 01000008: 00 ? 72
64 01000009: 00 ? 6c
65 0100000a: 00 ? 64
66 0100000b: 00 ? 0d
67 0100000c: 00 ? => <INTERRUPT>
68 => mm.b 0x101000
69 00101000: 00 ? 48
70 00101001: 00 ? 65
71 00101002: 00 ? 6c
72 00101003: 00 ? 6c
73 00101004: 00 ? 6f
74 00101005: 00 ? 20
75 00101006: 00 ? 57
76 00101007: 00 ? 6f
77 00101008: 00 ? 72
78 00101009: 00 ? 6c
79 0010100a: 00 ? 64
80 0010100b: 00 ? 0d
81 0010100c: 00 ? => <INTERRUPT>
82 => cmp 0x1000000 0x101000 0xc
83 word at 0x01000004 (0x6f77206f) != word at 0x00101004 (0x6f57206f)
84 Total of 1 word(s) were the same
85 => cmp.b 0x1000000 0x101000 0xc
86 byte at 0x01000006 (0x77) != byte at 0x00101006 (0x57)
87 Total of 6 byte(s) were the same
88 => cmp.w 0x1000000 0x101000 0xc
89 halfword at 0x01000006 (0x6f77) != halfword at 0x00101006 (0x6f57)
90 Total of 3 halfword(s) were the same
91 => cmp.l 0x1000000 0x101000 0xc
92 word at 0x01000004 (0x6f77206f) != word at 0x00101004 (0x6f57206f)
93 Total of 1 word(s) were the same
94 => cmp.q 0x1000000 0x101000 0xc
95 double word at 0x01000000 (0x6f77206f6c6c6548) != double word at 0x00101000 (0x6f57206f6c6c6548)
96 Total of 0 double word(s) were the same
97
98Configuration
99-------------
100
101The cmp command is only available if CONFIG_CMD_MEMORY=y. The cmp.q command is
Rasmus Villemoesdd5b9582024-01-03 11:47:10 +0100102only available on 64-bit targets.
Heinrich Schuchardt50cd4ce2022-11-13 13:27:32 +0100103
104Return value
105------------
106
107The return value $? is true (0) if the compared memory areas are equal.
108The reutrn value is false (1) if the compared memory areas differ.