Write SRC machine codes in both binary and hexadecimal for the following assembl
ID: 669413 • Letter: W
Question
Write SRC machine codes in both binary and hexadecimal for the following assembly codes. For unused bits, mark ‘x’ in binary and assume that those bits are ‘0’ when converting to hexadecimal. For example, binary 101x = hexadecimal 0xA
In C: #define Cost =125
If (X<0) then X = -X;
-------------------------------------------------------------------------------------------
In SRC:
Cost .equ 125; define symbolic constant
.org 1000; next word will be loaded at address 100010
X: .dw 1; reserve 1 word for variable X
.org 5000; program will be loaded at location 500010
lar r31, Over ;load address of “false” jump location
ld r1, X ;load value of X into r1
brpl r31, r1 ;branch to Else if r10
neg r1, r1 ;negate value
Over: • • •; continue
Over: addi r1, r1, Cost
st r1, X
Explanation / Answer
Given C program
---------------------------
#include <stdio.h>
#define Cost =125
main(void)
{
int X;
if (X<0)
X = -X;
}
-----------------------------------------------------------------------------------
Hexadecimal code:
.Ltext0:
.globl main
main:
.LFB0:
.cfi_startproc
0000 55 pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
0001 4889E5 movq %rsp, %rbp
.cfi_def_cfa_register 6
0004 837DFC00 cmpl $0, -4(%rbp)
0008 7903 jns .L2
000a F75DFC negl -4(%rbp)
.L2:
000d B8000000 movl $0, %eax
00
0012 5D popq %rbp
.cfi_def_cfa 7, 8
0013 C3 ret
.cfi_endproc
.LFE0:
.Letext0:
-----------------------------------------------------------------
binary:
----------
0000 55 ------> 0000 0000 0000 0000 0101 0101
0001 4889E5 -----> 0000 0000 0000 0001 0100 1000 1000 1001 1110 0101
0004 837DFC00 ---> 0000 0000 0000 0100 1000 0011 0111 1101 1111 1100 0000 0000
0008 7903 ------> 0000 0000 0000 1000 0111 1001 0000 0011
000a F75DFC -----> 0000 0000 0000 1010 1111 0111 0101 1101 1111 1100
000d B8000000 ---> 0000 0000 0000 1101 1011 1000 0000 0000 0000 0000 0000 0000
0012 5D --------> 0000 0000 0001 0010 0101 1101
0013 C3 ---------> 0000 0000 0001 0011 1100 0011
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.